Notes about difficulties of DI for scripts

This commit is contained in:
P0nk
2023-03-18 15:42:34 +01:00
parent 02c1fe46f3
commit 290bf78db3
4 changed files with 10 additions and 8 deletions

View File

@@ -84,7 +84,6 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
private String scriptName;
private String getText;
private boolean itemScript;
private List<PartyCharacter> otherParty;
private final Map<Integer, String> npcDefaultTalks = new HashMap<>();
@@ -102,11 +101,10 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
this(c, npc, -1, scriptName, false);
}
public NPCConversationManager(Client c, int npc, List<PartyCharacter> otherParty, boolean test) {
public NPCConversationManager(Client c, int npc) {
super(c);
this.c = c;
this.npc = npc;
this.otherParty = otherParty;
}
public NPCConversationManager(Client c, int npc, int oid, String scriptName, boolean itemScript) {
@@ -377,6 +375,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
}
public void openShopNPC(int id) {
// TODO: figure out a way to inject ShopFactory.
// NPCConversationManager is instantiated by NPCScriptManager, which is a static singleton.
// NPCScriptManager is accessed from all over, making it really difficult to structure dependencies properly.
Shop shop = ShopFactory.getInstance().getShop(id);
if (shop != null) {
@@ -1095,4 +1096,4 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
return false;
}
}
}

View File

@@ -82,7 +82,7 @@ public class NPCScriptManager extends AbstractScriptManager {
public void start(String filename, Client c, int npc, List<PartyCharacter> chrs) {
try {
final NPCConversationManager cm = new NPCConversationManager(c, npc, chrs, true);
final NPCConversationManager cm = new NPCConversationManager(c, npc);
cm.dispose();
if (cms.containsKey(c)) {
return;