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-2015 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();
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 }
static TestGameObject newGameObject(@NotNull final GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > gameObjectFactory, @NotNull final TestArchetype archetype, @NotNull final String gameObjectName)
Creates a new TestGameObject instance.
A FaceObjects for regression tests.
void testTypeNrsGameObjectMatcher2()
Checks that a NamedGameObjectMatcher works correctly when using an environment check.
Interface for classes that match GameObjects.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
An AnimationObjects for regression tests.
FaceObjectProviders newFaceObjectProviders()
Creates a new FaceObjectProviders instance.
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
A MapArchObject implementation for testing purposes.
String TYPE
The attribute name of the object&#39;s type.
Definition: BaseObject.java:66
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
An Archetype implementation for testing purposes.
Abstract factory for creating GameObject instances.
static TestArchetype newArchetype(@NotNull final String archetypeName, final int typeNo, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new TestArchetype instance.
void testTypeNrsGameObjectMatcher1()
Checks that a NamedGameObjectMatcher works correctly when not using an environment check...
AnimationObjects is a container for AnimationObjects.
GameObjects are the objects based on Archetypes found on maps.
final ResourceIcons resourceIcons
The ResourceIcons instance.
FaceObjects is a container for FaceObjects.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
Creates ImageIcon instances from resources.
String NAME
The attribute name of the object&#39;s name.
Definition: BaseObject.java:60
An Archetype implementation for testing purposes.
An GameObjectMatcher matching certain archetype types.
A GameObject implementation for testing purposes.
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.
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches an GameObject.