-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package common.entity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* A way to identify entities that should be much more resistant to collisions than a simple increasing integer. | ||
* | ||
* @param originWorld The game-world where this entity originated, in case it travels to anotheer world. | ||
* @param creatingPlayer The ID numbeer of the player whose action caused the entity to be created, or a negative ID | ||
* if it was not created due to player action. | ||
* @param id A unique identifying number for the entity. | ||
*/ | ||
public record ComplexIdentifier(@NotNull String originWorld, int creatingPlayer, @NotNull UUID id) { | ||
public ComplexIdentifier { | ||
if (creatingPlayer < -1) { | ||
throw new IllegalArgumentException("Player ID must be -1 if unknown, or nonnegative"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package common.entity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* An entity can be located in a particular region of a map at particular coordinates. Note that this class cannot | ||
* check region or coordinate upper bounds. | ||
* | ||
* @param world The world in which the region is located | ||
* @param region The ID of the region. TODO: Is this how we want to identify regions? | ||
* @param row The row within the region where the entity is located | ||
* TODO: Is row/column how we want to represent position within a region? | ||
* @param column The column within the region where the entity is located | ||
*/ | ||
public record CoordinateLocation(@NotNull String world, int region, int row, int column) implements Location { | ||
public CoordinateLocation { | ||
if (region < -1) { | ||
throw new IllegalArgumentException("Region must be -1 if unknown, or nonnegative"); | ||
} else if (region < 0 && (row >= 0 || column >= 0)) { | ||
throw new IllegalArgumentException("Coordinates cannot be known if region is unknown"); | ||
} else if ((row < 0 && column >= 0) || (row >= 0 && column < 0)) { | ||
throw new IllegalArgumentException("Either both or neither row and column must be valid"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package common.entity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Entity implements IEntity { | ||
public Entity(final @NotNull EntityIdentifier id, final @NotNull Location location) { | ||
this.location = location; | ||
this.id = id; | ||
} | ||
private @NotNull Location location; | ||
private final @NotNull EntityIdentifier id; | ||
private final Map<String, Object> properties = new HashMap<>(); | ||
@Override | ||
public final @NotNull Location getLocation() { | ||
return location; | ||
} | ||
|
||
public final void setLocation(final @NotNull Location location) { | ||
this.location = location; | ||
} | ||
@Override | ||
public final @NotNull EntityIdentifier getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public final boolean hasProperty(final @NotNull String propertyName) { | ||
return properties.containsKey(propertyName); | ||
} | ||
|
||
@Override | ||
public final @Nullable Class<?> getPropertyType(final @NotNull String propertyName) { | ||
final Object property = properties.get(propertyName); | ||
if (null == property) { | ||
return null; | ||
} else { | ||
return property.getClass(); | ||
} | ||
} | ||
|
||
@Override | ||
public final @Nullable Object getProperty(final @NotNull String propertyName) { | ||
return properties.get(propertyName); | ||
} | ||
|
||
@Override | ||
public final <T> @Nullable T getTypedProperty(final @NotNull String propertyName, final @NotNull Class<T> type) { | ||
final Object retval = properties.get(propertyName); | ||
if (type.isInstance(retval)) { | ||
return type.cast(retval); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public void setProperty(final @NotNull String propertyName, final @Nullable Object value) { | ||
if (value == null) { | ||
properties.remove(propertyName); | ||
} else { | ||
properties.put(propertyName, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package common.entity; | ||
|
||
/** | ||
* An interface for ways of identifying entities in the game-world. This is an interface to possibly allow us to import | ||
* maps from the 2009-2022 campaign, and to allow us to extend the format over time without breaking changes. | ||
* | ||
* TODO: What should the interface contain? | ||
*/ | ||
public interface EntityIdentifier { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package common.entity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* An interface for game-world entities. | ||
*/ | ||
public interface IEntity { | ||
@NotNull Location getLocation(); | ||
@NotNull EntityIdentifier getId(); | ||
boolean hasProperty(@NotNull String propertyName); | ||
@Nullable Class<?> getPropertyType(@NotNull String propertyName); | ||
@Nullable Object getProperty(@NotNull String propertyName); | ||
@Nullable <T> T getTypedProperty(@NotNull String propertyName, @NotNull Class<T> type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package common.entity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* An entity can be located within, or "at the same location as", another entity. Care will need to be taken to ensure | ||
* there are no location loops. | ||
* @param parent The entity that is the parent of the one this location object is embedded in. | ||
*/ | ||
public record InParentLocation(@NotNull EntityIdentifier parent) implements Location { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package common.entity; | ||
|
||
/** | ||
* In the 2009-2022 campaing, "fixtures" in the map were identified using a single integer, starting from 0 and | ||
* counting up. | ||
* | ||
* TODO: Maybe add an "origin world" parameter, defaulting to "prime"? | ||
* | ||
* @param idNumber the ID number | ||
*/ | ||
public record LegacyIdentifier(int idNumber) implements EntityIdentifier { | ||
public LegacyIdentifier { | ||
if (idNumber < -1) { | ||
throw new IllegalArgumentException("ID number must be -1 if unspecified, or else nonnegative"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package common.entity; | ||
|
||
/** | ||
* An inteerface for where something in the game-world could be located. A marker interface to start with, since | ||
* we will want to support both "inside such-and-such parent," "somewhere in such-and-such region," and "at | ||
* such-and-such coordiantes in such-and-such region". | ||
* | ||
* TODO: What should the interface contain? | ||
*/ | ||
public interface Location { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package common.entity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* An entity can be located at an unspecified location in a region. | ||
*/ | ||
public record RegionLocation(@NotNull String world, int region) implements Location { | ||
public RegionLocation { | ||
if (region < -1) { | ||
throw new IllegalArgumentException("Region must be -1 if unspecified, or else non-negative"); | ||
} | ||
} | ||
} |