From 7018703ba6f078f0d43841af4da96fae0fc8b739 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Mon, 23 Jun 2025 15:15:16 +0200 Subject: [PATCH] extract linkIcon --- src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java | 7 ++++++- src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java | 6 ++---- src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java | 6 +----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java index db511b1..42081a0 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java @@ -30,7 +30,12 @@ public final class Common { linkConditions(effect.conditions_source, proj, backlink); } } - + public static void linkIcon(Project proj, String iconId, GameDataElement backlink) { + if (iconId != null) { + String spritesheetId = iconId.split(":")[0]; + proj.getSpritesheet(spritesheetId).addBacklink(backlink); + } + } public static class TimedActorConditionEffect extends ActorConditionEffect { //Available from parsed state public Integer duration = null; diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java index 58ee109..34525ab 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java @@ -216,10 +216,7 @@ public class Item extends JSONElement { return; } - if (this.icon_id != null) { - String spritesheetId = this.icon_id.split(":")[0]; - proj.getSpritesheet(spritesheetId).addBacklink(this); - } + linkIcon(proj, this.icon_id, this); if (this.category_id != null) this.category = proj.getItemCategory(this.category_id); if (this.category != null) this.category.addBacklink(this); if (this.equip_effect != null && this.equip_effect.conditions != null) { @@ -232,6 +229,7 @@ public class Item extends JSONElement { this.state = State.linked; } + @Override public Image getIcon() { return getProject().getIcon(icon_id); diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java index 71e7fb5..f63598b 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java @@ -219,11 +219,7 @@ public class NPC extends JSONElement { Notification.addError("Error linking item " + id + ". No parent project found."); return; } - if (this.icon_id != null) { - String spritesheetId = this.icon_id.split(":")[0]; - proj.getSpritesheet(spritesheetId).addBacklink(this); - } - + linkIcon(proj, this.icon_id, this); if (this.dialogue_id != null) this.dialogue = proj.getDialogue(this.dialogue_id); if (this.dialogue != null) this.dialogue.addBacklink(this);