From c643bcb8fb8b636f28aea2dba06f80de52c34ec6 Mon Sep 17 00:00:00 2001 From: Wyatt Jacob Herkamp Date: Wed, 23 Dec 2020 20:14:36 -0500 Subject: [PATCH 1/5] Added ServerPlayer --- .../common/annotations/ModelDataFile.java | 6 +++++ .../core/common/game/CustomStackable.java | 7 ++++++ .../org/kakara/core/common/game/Item.java | 4 ++++ .../kakara/core/common/game/ItemStack.java | 3 +++ .../kakara/core/common/game/md/ModelData.java | 6 +++++ .../core/common/game/md/ModelDataObject.java | 23 +++++++++++++++++++ .../core/common/game/meta/ItemMeta.java | 5 ++++ .../kakara/core/common/mod/game/ModItem.java | 19 +++++++++++---- .../core/common/mod/game/ModelDataLoader.java | 10 ++++++++ .../core/server/game/ServerItemStack.java | 3 +++ .../core/server/game/meta/ServerItemMeta.java | 8 +++++++ 11 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/ModelData.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java create mode 100644 common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java create mode 100644 common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java create mode 100644 server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java diff --git a/common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java b/common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java new file mode 100644 index 0000000..38cd0bc --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java @@ -0,0 +1,6 @@ +package org.kakara.core.common.annotations; + +public @interface ModelDataFile { + String value(); +} + diff --git a/common/src/main/java/org/kakara/core/common/game/CustomStackable.java b/common/src/main/java/org/kakara/core/common/game/CustomStackable.java index 24eb10a..50c8e8f 100644 --- a/common/src/main/java/org/kakara/core/common/game/CustomStackable.java +++ b/common/src/main/java/org/kakara/core/common/game/CustomStackable.java @@ -10,4 +10,11 @@ public interface CustomStackable { * @return the custom item stack */ ItemStack createItemStack(); + + /** + * Create a custom ServerItemStack with your item. + * + * @return the custom item stack + */ + ItemStack createServerItemStack(); } diff --git a/common/src/main/java/org/kakara/core/common/game/Item.java b/common/src/main/java/org/kakara/core/common/game/Item.java index f896fb7..1984833 100644 --- a/common/src/main/java/org/kakara/core/common/game/Item.java +++ b/common/src/main/java/org/kakara/core/common/game/Item.java @@ -4,15 +4,19 @@ import org.kakara.core.common.ControllerKey; import org.kakara.core.common.GameObject; import org.kakara.core.common.Identifiable; +import org.kakara.core.common.game.md.ModelData; import org.kakara.core.common.mod.Mod; public interface Item extends Identifiable, GameObject { String getName(); + @Deprecated String getTexture(); + @Deprecated String getModel(); + ModelData getModelData(); ControllerKey getControllerKey(); diff --git a/common/src/main/java/org/kakara/core/common/game/ItemStack.java b/common/src/main/java/org/kakara/core/common/game/ItemStack.java index 0c85576..9796d3e 100644 --- a/common/src/main/java/org/kakara/core/common/game/ItemStack.java +++ b/common/src/main/java/org/kakara/core/common/game/ItemStack.java @@ -2,6 +2,7 @@ import org.kakara.core.common.Serverable; +import org.kakara.core.common.game.meta.ItemMeta; import java.util.List; @@ -28,4 +29,6 @@ public interface ItemStack extends Serverable { List getLore(); boolean equalsIgnoreCount(ItemStack itemStack); + + ItemMeta getItemMeta(); } diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelData.java b/common/src/main/java/org/kakara/core/common/game/md/ModelData.java new file mode 100644 index 0000000..cf68d81 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelData.java @@ -0,0 +1,6 @@ +package org.kakara.core.common.game.md; + +public interface ModelData { + ModelDataObject getModelDataObject(int id); + +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java b/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java new file mode 100644 index 0000000..916bf2b --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java @@ -0,0 +1,23 @@ +package org.kakara.core.common.game.md; + +import org.kakara.core.common.annotations.Model; +import org.kakara.core.common.resources.Texture; + +//TODO think of better name. +public class ModelDataObject { + private Texture texture; + private Model model; + + public ModelDataObject(Texture texture, Model model) { + this.texture = texture; + this.model = model; + } + + public Texture getTexture() { + return texture; + } + + public Model getModel() { + return model; + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java b/common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java new file mode 100644 index 0000000..902419b --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java @@ -0,0 +1,5 @@ +package org.kakara.core.common.game.meta; + +public interface ItemMeta { + int getModelData(); +} diff --git a/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java b/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java index c8b7c62..8cce762 100644 --- a/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java +++ b/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java @@ -2,12 +2,10 @@ import org.kakara.core.common.ControllerKey; -import org.kakara.core.common.annotations.Key; -import org.kakara.core.common.annotations.Model; -import org.kakara.core.common.annotations.Name; -import org.kakara.core.common.annotations.Texture; +import org.kakara.core.common.annotations.*; import org.kakara.core.common.game.Item; import org.kakara.core.common.game.SimpleGameObject; +import org.kakara.core.common.game.md.ModelData; import org.kakara.core.common.mod.Mod; import java.util.Objects; @@ -18,6 +16,7 @@ public abstract class ModItem extends SimpleGameObject implements Item { protected final String name; protected final int id; protected String texture; + private ModelData modelData; public ModItem(GameMod mod) { super(); @@ -28,6 +27,18 @@ public ModItem(GameMod mod) { this.nameKey = new ControllerKey(mod, keyA == null ? getClass().getSimpleName() : keyA.value()); this.id = nameKey.hashCode(); texture = getClass().getAnnotation(Texture.class).value(); + if (getClass().isAnnotationPresent(ModelDataFile.class)) { + modelData = ModelDataLoader.loadData(getClass().getAnnotation(ModelDataFile.class).value()); + } + } + + protected void setModelData(ModelData modelData) { + this.modelData = modelData; + } + + @Override + public ModelData getModelData() { + return modelData; } @Override diff --git a/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java b/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java new file mode 100644 index 0000000..16b65a8 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java @@ -0,0 +1,10 @@ +package org.kakara.core.common.mod.game; + +import org.kakara.core.common.game.md.ModelData; + +public class ModelDataLoader { + public static ModelData loadData(String value) { + //TODO Implement class + return null; + } +} diff --git a/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java b/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java index 970c592..1d423f3 100644 --- a/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java +++ b/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java @@ -3,6 +3,7 @@ import org.kakara.core.common.Serverable; import org.kakara.core.common.exceptions.NoServerVersionAvailableException; import org.kakara.core.common.game.ItemStack; +import org.kakara.core.common.game.meta.ItemMeta; import java.util.List; @@ -13,6 +14,8 @@ public interface ServerItemStack extends ItemStack { void setLore(List lore); + void setItemMeta(ItemMeta itemMeta); + ItemStack clone(); @Override diff --git a/server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java b/server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java new file mode 100644 index 0000000..626ae5f --- /dev/null +++ b/server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java @@ -0,0 +1,8 @@ +package org.kakara.core.server.game.meta; + +import org.kakara.core.common.game.meta.ItemMeta; + +public interface ServerItemMeta extends ItemMeta { + + void setModelData(int modelData); +} From d0deda4a6f4ebb299f5b7c7e17f69d557a84b692 Mon Sep 17 00:00:00 2001 From: Wyatt Jacob Herkamp Date: Wed, 23 Dec 2020 20:14:36 -0500 Subject: [PATCH 2/5] Added a basic ModelData system. --- .../common/annotations/ModelDataFile.java | 6 +++++ .../core/common/game/CustomStackable.java | 7 ++++++ .../org/kakara/core/common/game/Item.java | 4 ++++ .../kakara/core/common/game/ItemStack.java | 3 +++ .../kakara/core/common/game/md/ModelData.java | 6 +++++ .../core/common/game/md/ModelDataObject.java | 23 +++++++++++++++++++ .../core/common/game/meta/ItemMeta.java | 5 ++++ .../kakara/core/common/mod/game/ModItem.java | 19 +++++++++++---- .../core/common/mod/game/ModelDataLoader.java | 10 ++++++++ .../core/server/game/ServerItemStack.java | 3 +++ .../core/server/game/meta/ServerItemMeta.java | 8 +++++++ 11 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/ModelData.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java create mode 100644 common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java create mode 100644 common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java create mode 100644 server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java diff --git a/common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java b/common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java new file mode 100644 index 0000000..38cd0bc --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/annotations/ModelDataFile.java @@ -0,0 +1,6 @@ +package org.kakara.core.common.annotations; + +public @interface ModelDataFile { + String value(); +} + diff --git a/common/src/main/java/org/kakara/core/common/game/CustomStackable.java b/common/src/main/java/org/kakara/core/common/game/CustomStackable.java index 24eb10a..50c8e8f 100644 --- a/common/src/main/java/org/kakara/core/common/game/CustomStackable.java +++ b/common/src/main/java/org/kakara/core/common/game/CustomStackable.java @@ -10,4 +10,11 @@ public interface CustomStackable { * @return the custom item stack */ ItemStack createItemStack(); + + /** + * Create a custom ServerItemStack with your item. + * + * @return the custom item stack + */ + ItemStack createServerItemStack(); } diff --git a/common/src/main/java/org/kakara/core/common/game/Item.java b/common/src/main/java/org/kakara/core/common/game/Item.java index f896fb7..1984833 100644 --- a/common/src/main/java/org/kakara/core/common/game/Item.java +++ b/common/src/main/java/org/kakara/core/common/game/Item.java @@ -4,15 +4,19 @@ import org.kakara.core.common.ControllerKey; import org.kakara.core.common.GameObject; import org.kakara.core.common.Identifiable; +import org.kakara.core.common.game.md.ModelData; import org.kakara.core.common.mod.Mod; public interface Item extends Identifiable, GameObject { String getName(); + @Deprecated String getTexture(); + @Deprecated String getModel(); + ModelData getModelData(); ControllerKey getControllerKey(); diff --git a/common/src/main/java/org/kakara/core/common/game/ItemStack.java b/common/src/main/java/org/kakara/core/common/game/ItemStack.java index 0c85576..9796d3e 100644 --- a/common/src/main/java/org/kakara/core/common/game/ItemStack.java +++ b/common/src/main/java/org/kakara/core/common/game/ItemStack.java @@ -2,6 +2,7 @@ import org.kakara.core.common.Serverable; +import org.kakara.core.common.game.meta.ItemMeta; import java.util.List; @@ -28,4 +29,6 @@ public interface ItemStack extends Serverable { List getLore(); boolean equalsIgnoreCount(ItemStack itemStack); + + ItemMeta getItemMeta(); } diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelData.java b/common/src/main/java/org/kakara/core/common/game/md/ModelData.java new file mode 100644 index 0000000..cf68d81 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelData.java @@ -0,0 +1,6 @@ +package org.kakara.core.common.game.md; + +public interface ModelData { + ModelDataObject getModelDataObject(int id); + +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java b/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java new file mode 100644 index 0000000..916bf2b --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java @@ -0,0 +1,23 @@ +package org.kakara.core.common.game.md; + +import org.kakara.core.common.annotations.Model; +import org.kakara.core.common.resources.Texture; + +//TODO think of better name. +public class ModelDataObject { + private Texture texture; + private Model model; + + public ModelDataObject(Texture texture, Model model) { + this.texture = texture; + this.model = model; + } + + public Texture getTexture() { + return texture; + } + + public Model getModel() { + return model; + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java b/common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java new file mode 100644 index 0000000..902419b --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/meta/ItemMeta.java @@ -0,0 +1,5 @@ +package org.kakara.core.common.game.meta; + +public interface ItemMeta { + int getModelData(); +} diff --git a/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java b/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java index c8b7c62..8cce762 100644 --- a/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java +++ b/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java @@ -2,12 +2,10 @@ import org.kakara.core.common.ControllerKey; -import org.kakara.core.common.annotations.Key; -import org.kakara.core.common.annotations.Model; -import org.kakara.core.common.annotations.Name; -import org.kakara.core.common.annotations.Texture; +import org.kakara.core.common.annotations.*; import org.kakara.core.common.game.Item; import org.kakara.core.common.game.SimpleGameObject; +import org.kakara.core.common.game.md.ModelData; import org.kakara.core.common.mod.Mod; import java.util.Objects; @@ -18,6 +16,7 @@ public abstract class ModItem extends SimpleGameObject implements Item { protected final String name; protected final int id; protected String texture; + private ModelData modelData; public ModItem(GameMod mod) { super(); @@ -28,6 +27,18 @@ public ModItem(GameMod mod) { this.nameKey = new ControllerKey(mod, keyA == null ? getClass().getSimpleName() : keyA.value()); this.id = nameKey.hashCode(); texture = getClass().getAnnotation(Texture.class).value(); + if (getClass().isAnnotationPresent(ModelDataFile.class)) { + modelData = ModelDataLoader.loadData(getClass().getAnnotation(ModelDataFile.class).value()); + } + } + + protected void setModelData(ModelData modelData) { + this.modelData = modelData; + } + + @Override + public ModelData getModelData() { + return modelData; } @Override diff --git a/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java b/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java new file mode 100644 index 0000000..16b65a8 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java @@ -0,0 +1,10 @@ +package org.kakara.core.common.mod.game; + +import org.kakara.core.common.game.md.ModelData; + +public class ModelDataLoader { + public static ModelData loadData(String value) { + //TODO Implement class + return null; + } +} diff --git a/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java b/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java index 970c592..1d423f3 100644 --- a/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java +++ b/server/src/main/java/org/kakara/core/server/game/ServerItemStack.java @@ -3,6 +3,7 @@ import org.kakara.core.common.Serverable; import org.kakara.core.common.exceptions.NoServerVersionAvailableException; import org.kakara.core.common.game.ItemStack; +import org.kakara.core.common.game.meta.ItemMeta; import java.util.List; @@ -13,6 +14,8 @@ public interface ServerItemStack extends ItemStack { void setLore(List lore); + void setItemMeta(ItemMeta itemMeta); + ItemStack clone(); @Override diff --git a/server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java b/server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java new file mode 100644 index 0000000..626ae5f --- /dev/null +++ b/server/src/main/java/org/kakara/core/server/game/meta/ServerItemMeta.java @@ -0,0 +1,8 @@ +package org.kakara.core.server.game.meta; + +import org.kakara.core.common.game.meta.ItemMeta; + +public interface ServerItemMeta extends ItemMeta { + + void setModelData(int modelData); +} From 5b7885646db6e21e6ac53f19df45cdaeef81ddb4 Mon Sep 17 00:00:00 2001 From: Wyatt Jacob Herkamp Date: Thu, 24 Dec 2020 17:10:26 -0500 Subject: [PATCH 3/5] Improvements to the ModelData system --- .../core/common/game/md/ModelDataObject.java | 23 +++++++++++-------- .../common/game/md/ModelDataProperties.java | 7 ++++++ .../game/md/properties/ModelDataProperty.java | 8 +++++++ .../properties/json/BasicTextureProperty.java | 15 ++++++++++++ .../game/md/properties/json/JsonProperty.java | 9 ++++++++ .../md/properties/json/ModelProperty.java | 12 ++++++++++ .../json/TextureColorOffsetProperty.java | 8 +++++++ 7 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/org/kakara/core/common/game/md/ModelDataProperties.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/ModelDataProperty.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java b/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java index 916bf2b..38fd3a1 100644 --- a/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelDataObject.java @@ -1,23 +1,28 @@ package org.kakara.core.common.game.md; -import org.kakara.core.common.annotations.Model; +import org.kakara.core.common.game.md.properties.json.BasicTextureProperty; +import org.kakara.core.common.game.md.properties.json.ModelProperty; import org.kakara.core.common.resources.Texture; //TODO think of better name. public class ModelDataObject { - private Texture texture; - private Model model; + private final ModelDataProperties properties; + private final int id; - public ModelDataObject(Texture texture, Model model) { - this.texture = texture; - this.model = model; + public ModelDataObject(ModelDataProperties properties, int id) { + this.properties = properties; + this.id = id; } public Texture getTexture() { - return texture; + return ((BasicTextureProperty) properties.getProperty("TEXTURE")).getTexture(); } - public Model getModel() { - return model; + public String getModel() { + return ((ModelProperty) properties.getProperty("MODEL")).getModel(); + } + + public int getId() { + return id; } } diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelDataProperties.java b/common/src/main/java/org/kakara/core/common/game/md/ModelDataProperties.java new file mode 100644 index 0000000..138c325 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelDataProperties.java @@ -0,0 +1,7 @@ +package org.kakara.core.common.game.md; + +import org.kakara.core.common.game.md.properties.ModelDataProperty; + +public interface ModelDataProperties { + ModelDataProperty getProperty(String name); +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/ModelDataProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/ModelDataProperty.java new file mode 100644 index 0000000..bdb7b4b --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/ModelDataProperty.java @@ -0,0 +1,8 @@ +package org.kakara.core.common.game.md.properties; + +import org.kakara.core.common.game.md.ModelData; +import org.kakara.core.common.game.md.ModelDataProperties; + +public interface ModelDataProperty { + String propertyName(); +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java new file mode 100644 index 0000000..58c9f11 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java @@ -0,0 +1,15 @@ +package org.kakara.core.common.game.md.properties.json; + +import org.kakara.core.common.resources.Texture; + +public class BasicTextureProperty extends JsonProperty { + + @Override + public String propertyName() { + return "texture"; + } + + public Texture getTexture() { + return null; + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java new file mode 100644 index 0000000..0801d5c --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java @@ -0,0 +1,9 @@ +package org.kakara.core.common.game.md.properties.json; + +import org.kakara.core.common.game.md.properties.ModelDataProperty; + +public abstract class JsonProperty implements ModelDataProperty { + + + +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java new file mode 100644 index 0000000..9ae7cb3 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java @@ -0,0 +1,12 @@ +package org.kakara.core.common.game.md.properties.json; + +public class ModelProperty extends JsonProperty { + @Override + public String propertyName() { + return "MODEL"; + } + + public String getModel() { + return ""; + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java new file mode 100644 index 0000000..2d12e20 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java @@ -0,0 +1,8 @@ +package org.kakara.core.common.game.md.properties.json; + +public class TextureColorOffsetProperty extends JsonProperty { + @Override + public String propertyName() { + return "COLOR_OFFSET"; + } +} From 930068d2d65976836fc425cbafabe4773df02a21 Mon Sep 17 00:00:00 2001 From: Wyatt Jacob Herkamp Date: Fri, 25 Dec 2020 11:05:40 -0500 Subject: [PATCH 4/5] Added a ModelData loader --- .../kakara/core/common/game/md/ModelData.java | 3 ++ .../core/common/game/md/ModelDataLoader.java | 21 ++++++++++ .../properties/json/BasicTextureProperty.java | 7 +++- .../md/properties/json/JsonModelData.java | 33 ++++++++++++++++ .../properties/json/JsonModelDataLoader.java | 39 +++++++++++++++++++ .../json/JsonModelDataProperties.java | 19 +++++++++ .../game/md/properties/json/JsonProperty.java | 5 +++ .../md/properties/json/ModelProperty.java | 6 +++ .../json/TextureColorOffsetProperty.java | 6 +++ .../kakara/core/common/mod/game/ModItem.java | 5 ++- .../core/common/mod/game/ModelDataLoader.java | 10 ----- 11 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 common/src/main/java/org/kakara/core/common/game/md/ModelDataLoader.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelData.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataLoader.java create mode 100644 common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataProperties.java delete mode 100644 common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelData.java b/common/src/main/java/org/kakara/core/common/game/md/ModelData.java index cf68d81..1a0b27c 100644 --- a/common/src/main/java/org/kakara/core/common/game/md/ModelData.java +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelData.java @@ -3,4 +3,7 @@ public interface ModelData { ModelDataObject getModelDataObject(int id); + String getDefaultTexture(); + + String getDefaultModel(); } diff --git a/common/src/main/java/org/kakara/core/common/game/md/ModelDataLoader.java b/common/src/main/java/org/kakara/core/common/game/md/ModelDataLoader.java new file mode 100644 index 0000000..7b526a2 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/ModelDataLoader.java @@ -0,0 +1,21 @@ +package org.kakara.core.common.game.md; + +import com.google.gson.JsonObject; +import org.kakara.core.common.Utils; +import org.kakara.core.common.game.md.properties.json.JsonModelDataLoader; +import org.kakara.core.common.resources.Resource; + +import java.io.FileNotFoundException; +import java.io.FileReader; + +public class ModelDataLoader { + public static ModelData loadData(Resource resource) { + try { + JsonObject jsonObject = Utils.getGson().fromJson(new FileReader(resource.getFile()), JsonObject.class); + return JsonModelDataLoader.loadModelData(jsonObject); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java index 58c9f11..89a5a02 100644 --- a/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/BasicTextureProperty.java @@ -1,12 +1,17 @@ package org.kakara.core.common.game.md.properties.json; +import com.google.gson.JsonObject; import org.kakara.core.common.resources.Texture; public class BasicTextureProperty extends JsonProperty { + public BasicTextureProperty(JsonObject jsonObject) { + super(jsonObject); + } + @Override public String propertyName() { - return "texture"; + return "TEXTURE"; } public Texture getTexture() { diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelData.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelData.java new file mode 100644 index 0000000..1fe282e --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelData.java @@ -0,0 +1,33 @@ +package org.kakara.core.common.game.md.properties.json; + +import org.kakara.core.common.game.md.ModelData; +import org.kakara.core.common.game.md.ModelDataObject; + +import java.util.List; + +public class JsonModelData implements ModelData { + private final List modelDataObjects; + private final String defaultTexture; + private final String defaultModel; + + public JsonModelData(List modelDataObjects, String defaultTexture, String defaultModel) { + this.modelDataObjects = modelDataObjects; + this.defaultTexture = defaultTexture; + this.defaultModel = defaultModel; + } + + @Override + public ModelDataObject getModelDataObject(int id) { + return modelDataObjects.get(id); + } + + @Override + public String getDefaultTexture() { + return defaultTexture; + } + + @Override + public String getDefaultModel() { + return defaultModel; + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataLoader.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataLoader.java new file mode 100644 index 0000000..b8b1831 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataLoader.java @@ -0,0 +1,39 @@ +package org.kakara.core.common.game.md.properties.json; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.kakara.core.common.game.md.ModelData; +import org.kakara.core.common.game.md.ModelDataObject; +import org.kakara.core.common.game.md.properties.ModelDataProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class JsonModelDataLoader { + public static ModelData loadModelData(JsonObject object) { + + String defaultModel = object.get("default-model").getAsString(); + String defaultTexture = object.get("default-texture").getAsString(); + + List objectList = new ArrayList<>(); + if (object.has("models")) { + int i = 1; + for (JsonElement models : object.get("models").getAsJsonArray()) { + List properties = new ArrayList<>(); + for (Map.Entry stringJsonElementEntry : models.getAsJsonObject().entrySet()) { + String key = stringJsonElementEntry.getKey(); + + if (key.equalsIgnoreCase("TEXTURE")) { + properties.add(new BasicTextureProperty(stringJsonElementEntry.getValue().getAsJsonObject())); + } else if (key.equalsIgnoreCase("MODEL")) { + properties.add(new ModelProperty(stringJsonElementEntry.getValue().getAsJsonObject())); + } + } + i++; + objectList.add(new ModelDataObject(new JsonModelDataProperties(properties), i)); + } + } + return new JsonModelData(objectList, defaultTexture, defaultModel); + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataProperties.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataProperties.java new file mode 100644 index 0000000..396c7e0 --- /dev/null +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonModelDataProperties.java @@ -0,0 +1,19 @@ +package org.kakara.core.common.game.md.properties.json; + +import org.kakara.core.common.game.md.ModelDataProperties; +import org.kakara.core.common.game.md.properties.ModelDataProperty; + +import java.util.List; + +public class JsonModelDataProperties implements ModelDataProperties { + private final List propertyList; + + public JsonModelDataProperties(List propertyList) { + this.propertyList = propertyList; + } + + @Override + public ModelDataProperty getProperty(String name) { + return propertyList.stream().filter(modelDataProperty -> modelDataProperty.propertyName().equalsIgnoreCase(name)).findFirst().orElse(null); + } +} diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java index 0801d5c..508a3b5 100644 --- a/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/JsonProperty.java @@ -1,9 +1,14 @@ package org.kakara.core.common.game.md.properties.json; +import com.google.gson.JsonObject; import org.kakara.core.common.game.md.properties.ModelDataProperty; public abstract class JsonProperty implements ModelDataProperty { + private JsonObject jsonObject; + public JsonProperty(JsonObject jsonObject) { + this.jsonObject = jsonObject; + } } diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java index 9ae7cb3..1b063ee 100644 --- a/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/ModelProperty.java @@ -1,6 +1,12 @@ package org.kakara.core.common.game.md.properties.json; +import com.google.gson.JsonObject; + public class ModelProperty extends JsonProperty { + public ModelProperty(JsonObject jsonObject) { + super(jsonObject); + } + @Override public String propertyName() { return "MODEL"; diff --git a/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java b/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java index 2d12e20..612bba4 100644 --- a/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java +++ b/common/src/main/java/org/kakara/core/common/game/md/properties/json/TextureColorOffsetProperty.java @@ -1,6 +1,12 @@ package org.kakara.core.common.game.md.properties.json; +import com.google.gson.JsonObject; + public class TextureColorOffsetProperty extends JsonProperty { + public TextureColorOffsetProperty(JsonObject jsonObject) { + super(jsonObject); + } + @Override public String propertyName() { return "COLOR_OFFSET"; diff --git a/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java b/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java index 8cce762..5886e04 100644 --- a/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java +++ b/common/src/main/java/org/kakara/core/common/mod/game/ModItem.java @@ -2,11 +2,14 @@ import org.kakara.core.common.ControllerKey; +import org.kakara.core.common.Kakara; import org.kakara.core.common.annotations.*; import org.kakara.core.common.game.Item; import org.kakara.core.common.game.SimpleGameObject; import org.kakara.core.common.game.md.ModelData; +import org.kakara.core.common.game.md.ModelDataLoader; import org.kakara.core.common.mod.Mod; +import org.kakara.core.common.resources.ResourceType; import java.util.Objects; @@ -28,7 +31,7 @@ public ModItem(GameMod mod) { this.id = nameKey.hashCode(); texture = getClass().getAnnotation(Texture.class).value(); if (getClass().isAnnotationPresent(ModelDataFile.class)) { - modelData = ModelDataLoader.loadData(getClass().getAnnotation(ModelDataFile.class).value()); + modelData = ModelDataLoader.loadData(Kakara.getGameInstance().getResourceManager().getResource(getClass().getAnnotation(ModelDataFile.class).value(), ResourceType.OTHER, mod)); } } diff --git a/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java b/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java deleted file mode 100644 index 16b65a8..0000000 --- a/common/src/main/java/org/kakara/core/common/mod/game/ModelDataLoader.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.kakara.core.common.mod.game; - -import org.kakara.core.common.game.md.ModelData; - -public class ModelDataLoader { - public static ModelData loadData(String value) { - //TODO Implement class - return null; - } -} From 00fd9811538e415e77d400335d26cc7307c327e3 Mon Sep 17 00:00:00 2001 From: 7we Date: Sun, 27 Dec 2020 20:21:00 -0500 Subject: [PATCH 5/5] Added aggregatedJavadocs --- build.gradle.kts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index bcb46ce..64c11e0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,4 +15,22 @@ subprojects { maven("https://repo.maven.apache.org/maven2") maven("https://repo.kingtux.me/storages/maven/kakara") } + +} +tasks.register("aggregatedJavadocs") { + setDestinationDir(file("$buildDir/docs/javadoc")) + title = "$project.name $version API" + options.withGroovyBuilder { + "author"(true) + "addStringOption"("Xdoclint:none", "-quiet") + "addStringOption"("sourcepath", "") + } + subprojects.forEach { proj -> + proj.tasks.filterIsInstance().forEach { + source += it.source + classpath += it.classpath + excludes += it.excludes + includes += it.includes + } + } } \ No newline at end of file