Gridarta Editor
NamedGameObjectMatcherTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.match;
21 
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 import org.junit.Assert;
39 import org.junit.Test;
40 
46 
50  @Nullable
51  private final ResourceIcons resourceIcons = new ResourceIcons();
52 
57  @Test
59  final GameObjectMatcher invGameObjectMatcher = new TypeNrsGameObjectMatcher(1);
60  final GameObjectMatcher namedGameObjectMatcher = new NamedGameObjectMatcher(0, "namedGameObjectMatcher", "namedGameObjectMatcher", false, null, invGameObjectMatcher);
61  final FaceObjectProviders faceObjectProviders = newFaceObjectProviders();
62  final AnimationObjects animationObjects = new TestAnimationObjects();
63  final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects);
64  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1)));
65  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2)));
66  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 1)));
67  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 1)));
68  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 2)));
69  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 2)));
70  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 1, 1)));
71  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 2, 2)));
72  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 1, 2)));
73  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 2, 1)));
74  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 2, 2)));
75  }
76 
81  @Test
83  final GameObjectMatcher invGameObjectMatcher = new TypeNrsGameObjectMatcher(1);
84  final GameObjectMatcher envGameObjectMatcher = new TypeNrsGameObjectMatcher(2);
85  final GameObjectMatcher namedGameObjectMatcher = new NamedGameObjectMatcher(0, "namedGameObjectMatcher", "namedGameObjectMatcher", false, envGameObjectMatcher, invGameObjectMatcher);
86  final FaceObjectProviders faceObjectProviders = newFaceObjectProviders();
87  final AnimationObjects animationObjects = new TestAnimationObjects();
88  final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects);
89  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1)));
90  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2)));
91  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 1)));
92  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 1)));
93  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 2)));
94  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 2)));
95  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 1, 1)));
96  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 1, 2, 2)));
97  Assert.assertTrue(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 1, 2)));
98  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 2, 1)));
99  Assert.assertFalse(namedGameObjectMatcher.isMatching(newGameObjects(gameObjectFactory, faceObjectProviders, animationObjects, 2, 2, 2)));
100  }
101 
111  @NotNull
112  private static TestArchetype newArchetype(@NotNull final String archetypeName, final int typeNo, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects) {
113  final TestArchetype archetype = new TestDefaultArchetype(archetypeName, faceObjectProviders, animationObjects);
114  archetype.setAttributeInt(BaseObject.TYPE, typeNo);
115  return archetype;
116  }
117 
125  @NotNull
126  private static TestGameObject newGameObject(@NotNull final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory, @NotNull final TestArchetype archetype, @NotNull final String gameObjectName) {
127  final TestGameObject gameObject = gameObjectFactory.createGameObject(archetype);
128  gameObject.setAttributeString(BaseObject.NAME, gameObjectName);
129  return gameObject;
130  }
131 
143  @NotNull
144  private static GameObject<?, ?, ?> newGameObjects(@NotNull final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final int... typeNumbers) {
145  TestGameObject gameObject = null;
146  for (final int typeNumber : typeNumbers) {
147  final String name = Integer.toString(typeNumber);
148  final TestArchetype archetype = newArchetype("arch" + name, typeNumber, faceObjectProviders, animationObjects);
149  final TestGameObject tmp = newGameObject(gameObjectFactory, archetype, name);
150  if (gameObject != null) {
151  tmp.addLast(gameObject);
152  }
153  gameObject = tmp;
154  }
155  if (gameObject == null) {
156  throw new IllegalArgumentException("no matching game objects found");
157  }
158  return gameObject;
159  }
160 
166  final FaceObjects faceObjects = new TestFaceObjects();
167  assert resourceIcons != null;
168  return new FaceObjectProviders(0, faceObjects, resourceIcons);
169  }
170 
171 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.archetype.TestDefaultArchetype
An Archetype implementation for testing purposes.
Definition: TestDefaultArchetype.java:32
net.sf.gridarta.model.gameobject.GameObjectFactory
Abstract factory for creating GameObject instances.
Definition: GameObjectFactory.java:31
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.newFaceObjectProviders
FaceObjectProviders newFaceObjectProviders()
Creates a new FaceObjectProviders instance.
Definition: NamedGameObjectMatcherTest.java:165
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.anim.AnimationObjects
AnimationObjects is a container for AnimationObjects.
Definition: AnimationObjects.java:30
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.newGameObject
static TestGameObject newGameObject(@NotNull final GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > gameObjectFactory, @NotNull final TestArchetype archetype, @NotNull final String gameObjectName)
Creates a new TestGameObject instance.
Definition: NamedGameObjectMatcherTest.java:126
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.testTypeNrsGameObjectMatcher1
void testTypeNrsGameObjectMatcher1()
Checks that a NamedGameObjectMatcher works correctly when not using an environment check.
Definition: NamedGameObjectMatcherTest.java:58
net.sf.gridarta.model.match.GameObjectMatcher
Interface for classes that match GameObjects.
Definition: GameObjectMatcher.java:30
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.baseobject.BaseObject.NAME
String NAME
The attribute name of the object's name.
Definition: BaseObject.java:60
net.sf.gridarta.model.anim.TestAnimationObjects
An AnimationObjects for regression tests.
Definition: TestAnimationObjects.java:26
net.sf.gridarta.model.match.GameObjectMatcher.isMatching
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches a GameObject.
net.sf.gridarta.model.match.NamedGameObjectMatcher
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Definition: NamedGameObjectMatcher.java:33
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.match.TypeNrsGameObjectMatcher
An GameObjectMatcher matching certain archetype types.
Definition: TypeNrsGameObjectMatcher.java:30
net.sf.gridarta.model.gameobject.TestGameObjectFactory
A GameObjectFactory for regression tests.
Definition: TestGameObjectFactory.java:34
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.testTypeNrsGameObjectMatcher2
void testTypeNrsGameObjectMatcher2()
Checks that a NamedGameObjectMatcher works correctly when using an environment check.
Definition: NamedGameObjectMatcherTest.java:82
net.sf.gridarta.model.face.FaceObjects
FaceObjects is a container for FaceObjects.
Definition: FaceObjects.java:31
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.newArchetype
static TestArchetype newArchetype(@NotNull final String archetypeName, final int typeNo, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new TestArchetype instance.
Definition: NamedGameObjectMatcherTest.java:112
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.resourceIcons
final ResourceIcons resourceIcons
The ResourceIcons instance.
Definition: NamedGameObjectMatcherTest.java:51
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.match.NamedGameObjectMatcherTest
Regression tests for NamedGameObjectMatcher.
Definition: NamedGameObjectMatcherTest.java:45
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.anim
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Definition: AbstractAnimationObjects.java:20
net.sf.gridarta.var.crossfire.model.gameobject.GameObject<?, ?, ?>
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.utils.ResourceIcons
Creates ImageIcon instances from resources.
Definition: ResourceIcons.java:46
net.sf.gridarta.model.match.NamedGameObjectMatcherTest.newGameObjects
static GameObject<?, ?, ?> newGameObjects(@NotNull final GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > gameObjectFactory, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final int... typeNumbers)
Creates a chain of TestGameObject instances having the given type numbers.
Definition: NamedGameObjectMatcherTest.java:144
net.sf.gridarta.model.baseobject.BaseObject.TYPE
String TYPE
The attribute name of the object's type.
Definition: BaseObject.java:66
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.model.face.TestFaceObjects
A FaceObjects for regression tests.
Definition: TestFaceObjects.java:30