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