Add Script Context and better parsing for d.ts handling

This commit is contained in:
Kam authored and bigguy345 committed 2026-01-13 19:02:52 +02:00
1 parent cd92c340c7
commit 71dba15270
8 files changed
+253 -96

No files matched your search

@@ -23,6 +23,7 @@ import noppes.npcs.client.gui.util.ITextChangeListener;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.constants.ScriptContext;
import noppes.npcs.controllers.data.ForgeDataScript;
import noppes.npcs.controllers.data.IScriptHandler;
import noppes.npcs.controllers.data.IScriptUnit;
@@ -225,6 +226,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
// Set the script context for context-aware hook autocomplete
activeArea.setScriptContext(getScriptContext());
// Set the script context for context-aware hook autocomplete
activeArea.setScriptContext(getScriptContext());
// Setup fullscreen key binding
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
if (e.isPress()) {
@@ -627,96 +631,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
return ScriptContext.GLOBAL;
}
// ==================== UNIFIED SCRIPT DATA HANDLING ====================
/**
* Unified setGuiData for script GUIs with old container system.
* Handles both language data and tab-specific script loading.
*/
protected void setGuiDataWithOldContainer(NBTTagCompound compound) {
if (compound.hasKey("LoadComplete")) {
loaded = true;
return;
}
if (!compound.hasKey("Tab")) {
this.handler.setLanguage(compound.getString("ScriptLanguage"));
this.handler.setEnabled(compound.getBoolean("ScriptEnabled"));
this.loadLanguagesData(compound);
} else {
int tab = compound.getInteger("Tab");
ScriptContainer container = new ScriptContainer(this.handler);
container.readFromNBT(compound.getCompoundTag("Script"));
this.setHandlerContainer(container);
this.initGui();
}
}
/**
* Load languages data from NBT.
* Separated for potential override in subclasses if needed.
*/
protected void loadLanguagesData(NBTTagCompound compound) {
NBTTagList data = compound.getTagList("Languages", 10);
HashMap languages = new HashMap();
for (int i = 0; i < data.tagCount(); ++i) {
NBTTagCompound comp = data.getCompoundTagAt(i);
java.util.ArrayList scripts = new java.util.ArrayList();
NBTTagList list = comp.getTagList("Scripts", 8);
for (int j = 0; j < list.tagCount(); ++j) {
scripts.add(list.getStringTagAt(j));
}
languages.put(comp.getString("Language"), scripts);
}
this.languages = languages;
this.initGui();
}
/**
* Set the handler's container. Override if handler is not IScriptHandler.
*/
protected void setHandlerContainer(IScriptUnit container) {
// Default implementation - subclasses may need to cast and set differently
// e.g., ((LinkedItemScript) handler).container = container;
}
/**
* Unified save method for script GUIs with packet-based saving.
* Subclasses only need to override sendScriptPackets() and sendMetadataPacket().
*/
protected void saveWithPackets() {
if (loaded) {
this.setScript();
List<IScriptUnit> containers = this.handler.getScripts();
for (int i = 0; i < containers.size(); i++) {
IScriptUnit container = containers.get(i);
sendSavePacket(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
}
NBTTagCompound scriptData = new NBTTagCompound();
scriptData.setString("ScriptLanguage", this.handler.getLanguage());
scriptData.setBoolean("ScriptEnabled", this.handler.getEnabled());
scriptData.setTag("ScriptConsole", noppes.npcs.NBTTags.NBTLongStringMap(this.handler.getConsoleText()));
sendSavePacket(-1, containers.size(), scriptData);
}
}
/**
* Send a script container packet. Override in subclasses.
* @param index The index of this script
* @param totalCount Total number of scripts
* @param scriptNBT The script container NBT data
*/
protected void sendSavePacket(int index, int totalCount, NBTTagCompound scriptNBT) {
// Default: do nothing (for non-packet-based GUIs like GuiScriptItem)
}
public void save() {
if (loaded)
this.setScript();