working for, now writing
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// engine_logic.js - Reine State- und Datenverarbeitung (Kein UI, Kein Fetch)
|
||||
const EngineLogic = {
|
||||
storyData: { nodes: {} },
|
||||
state: { reboots: 1, node: "" },
|
||||
|
||||
init: function(dataObj) {
|
||||
if (!dataObj || !dataObj.nodes || Object.keys(dataObj.nodes).length === 0) {
|
||||
console.warn("[System] Ungültige Graph-Daten. Fallback geladen.");
|
||||
this.storyData = {
|
||||
startNodeId: "err",
|
||||
nodes: {
|
||||
"err": {
|
||||
id: "err", title: "SYSTEM OFFLINE",
|
||||
content: "<p>Konnte <code>graph.json</code> nicht laden.</p>",
|
||||
choices: [],
|
||||
metadata: { status: "offline" }
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
this.storyData = dataObj;
|
||||
}
|
||||
|
||||
this.state.node = this.storyData.startNodeId || Object.keys(this.storyData.nodes)[0] || "";
|
||||
},
|
||||
|
||||
getNode: function(id) { return this.storyData.nodes[id]; },
|
||||
|
||||
processNodeEntry: function(id) {
|
||||
const node = this.getNode(id);
|
||||
if (!node) return null;
|
||||
|
||||
this.state.node = id;
|
||||
|
||||
if (node.metadata) {
|
||||
Object.keys(node.metadata).forEach(key => {
|
||||
this.state[key] = node.metadata[key];
|
||||
});
|
||||
}
|
||||
|
||||
if (node.isReboot) this.state.reboots++;
|
||||
return node;
|
||||
},
|
||||
|
||||
parseRequirement: function(choiceText) {
|
||||
let conditionMatch = choiceText.match(/\[req:\s*([a-zA-Z0-9_]+)\s*=\s*([^\]]+)\]/i);
|
||||
let displayText = choiceText;
|
||||
let meetsCondition = true;
|
||||
let missingReq = "";
|
||||
|
||||
if (conditionMatch) {
|
||||
let reqKey = conditionMatch[1].toLowerCase();
|
||||
let reqVal = conditionMatch[2];
|
||||
if (String(this.state[reqKey]) !== String(reqVal)) {
|
||||
meetsCondition = false;
|
||||
missingReq = `(Benötigt: ${reqKey}=${reqVal})`;
|
||||
}
|
||||
displayText = displayText.replace(conditionMatch[0], "").trim();
|
||||
}
|
||||
|
||||
return { displayText, meetsCondition, missingReq };
|
||||
},
|
||||
|
||||
triggerReboot: function() {
|
||||
const currentReboots = this.state.reboots + 1;
|
||||
this.state = { reboots: currentReboots };
|
||||
return this.storyData.startNodeId;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user