Gridarta Editor
SmoothFaces.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.smoothface;
21 
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.TreeMap;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
36 public class SmoothFaces implements Iterable<Map.Entry<String, SmoothFace>> {
37 
41  @NotNull
42  private final Map<String, SmoothFace> smoothFaces = new TreeMap<>();
43 
47  @NotNull
48  private final FaceObjects faceObjects;
49 
54  public SmoothFaces(@NotNull final FaceObjects faceObjects) {
55  this.faceObjects = faceObjects;
56  }
57 
63  public void add(@NotNull final SmoothFace smoothFace) throws DuplicateSmoothFaceException {
64  final SmoothFace oldSmoothFace = smoothFaces.get(smoothFace.getFace());
65  if (oldSmoothFace != null) {
66  if (oldSmoothFace.getValue().equals(smoothFace.getValue())) {
67  return;
68  }
69 
70  throw new DuplicateSmoothFaceException(smoothFace.getFace(), smoothFace.getValue(), oldSmoothFace.getValue());
71  }
72 
73  smoothFaces.put(smoothFace.getFace(), smoothFace);
74  }
75 
82  @Nullable
83  public FaceObject getSmoothFace(@NotNull final GameObject<?, ?, ?> gameObject) {
84  String faceName = gameObject.getFaceName();
85  if (faceName == null) {
86  faceName = gameObject.getArchetype().getFaceName();
87  }
88  if (faceName == null) {
89  return null;
90  }
91  final SmoothFace smoothFace = smoothFaces.get(faceName);
92  if (smoothFace == null) {
93  return null;
94  }
95  return faceObjects.get(smoothFace.getValue());
96  }
97 
98  @NotNull
99  @Override
100  public Iterator<Map.Entry<String, SmoothFace>> iterator() {
101  return Collections.unmodifiableMap(smoothFaces).entrySet().iterator();
102  }
103 
104 }
final Map< String, SmoothFace > smoothFaces
The defined SmoothFaces.
FaceObject getSmoothFace(@NotNull final GameObject<?, ?, ?> gameObject)
Returns the smooth faces for a GameObject.
Common interface for FaceObject.
Definition: FaceObject.java:30
void add(@NotNull final SmoothFace smoothFace)
Adds a SmoothFace instance.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
final FaceObjects faceObjects
The FaceObjects for looking up faces.
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
Collection of all smoothing information.
Iterator< Map.Entry< String, SmoothFace > > iterator()
GameObjects are the objects based on Archetypes found on maps.
Smoothing information for one face name.
Definition: SmoothFace.java:28
FaceObjects is a container for FaceObjects.
The face is the appearance of an object.
String getFaceName()
Get the faceName, which is the name of the face as usable by the "face" attribute.
String getValue()
Returns the smooth information.
Definition: SmoothFace.java:66
SmoothFaces(@NotNull final FaceObjects faceObjects)
Creates a new instance.
Thrown to indicate that a SmoothFace instance is not unique.