From 33215a87b326ac5e443cd81c2cbf60ef5bda2dbc Mon Sep 17 00:00:00 2001 From: henk717 Date: Thu, 19 Aug 2021 13:48:33 +0200 Subject: [PATCH] Added VE_FORBRYDERNE's Selective World Info This update allows you to selectively choose when World Info is loaded for more control and RAM savings. --- .gitignore | 1 + aiserver.py | 51 ++++++++++++++++++----- static/application.js | 94 ++++++++++++++++++++++++++++++++++--------- static/custom.css | 10 +++-- 4 files changed, 125 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 8a6b218c..9f4241cd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ client.settings stories/* !stories/sample_story.json /.project +*.bak \ No newline at end of file diff --git a/aiserver.py b/aiserver.py index cb282e5b..8db499a1 100644 --- a/aiserver.py +++ b/aiserver.py @@ -506,6 +506,10 @@ def get_message(msg): addwiitem() elif(msg['cmd'] == 'widelete'): deletewi(msg['data']) + elif(msg['cmd'] == 'wiselon'): + vars.worldinfo[msg['data']]["selective"] = True + elif(msg['cmd'] == 'wiseloff'): + vars.worldinfo[msg['data']]["selective"] = False elif(msg['cmd'] == 'sendwilist'): commitwi(msg['data']) elif(msg['cmd'] == 'aidgimport'): @@ -1240,7 +1244,7 @@ def togglewimode(): # #==================================================================# def addwiitem(): - ob = {"key": "", "content": "", "num": len(vars.worldinfo), "init": False} + ob = {"key": "", "keysecondary": "", "content": "", "num": len(vars.worldinfo), "init": False, "selective": False} vars.worldinfo.append(ob); emit('from_server', {'cmd': 'addwiitem', 'data': ob}) @@ -1291,8 +1295,10 @@ def organizewi(): #==================================================================# def commitwi(ar): for ob in ar: - vars.worldinfo[ob["num"]]["key"] = ob["key"] - vars.worldinfo[ob["num"]]["content"] = ob["content"] + vars.worldinfo[ob["num"]]["key"] = ob["key"] + vars.worldinfo[ob["num"]]["keysecondary"] = ob["keysecondary"] + vars.worldinfo[ob["num"]]["content"] = ob["content"] + vars.worldinfo[ob["num"]]["selective"] = ob["selective"] # Was this a deletion request? If so, remove the requested index if(vars.deletewi >= 0): del vars.worldinfo[vars.deletewi] @@ -1345,14 +1351,29 @@ def checkworldinfo(txt): if(wi["key"] != ""): # Split comma-separated keys keys = wi["key"].split(",") + keys_secondary = wi.get("keysecondary", "").split(",") + for k in keys: ky = k # Remove leading/trailing spaces if the option is enabled if(vars.wirmvwhtsp): ky = k.strip() if ky in txt: - wimem = wimem + wi["content"] + "\n" - break + if wi.get("selective", False) and len(keys_secondary): + found = False + for ks in keys_secondary: + ksy = ks + if(vars.wirmvwhtsp): + ksy = ks.strip() + if ksy in txt: + wimem = wimem + wi["content"] + "\n" + found = True + break + if found: + break + else: + wimem = wimem + wi["content"] + "\n" + break return wimem @@ -1549,7 +1570,9 @@ def saveRequest(savpath): if(wi["key"] != ""): js["worldinfo"].append({ "key": wi["key"], - "content": wi["content"] + "keysecondary": wi["keysecondary"], + "content": wi["content"], + "selective": wi["selective"] }) # Write it @@ -1606,9 +1629,11 @@ def loadRequest(loadpath): for wi in js["worldinfo"]: vars.worldinfo.append({ "key": wi["key"], + "keysecondary": wi.get("keysecondary", ""), "content": wi["content"], "num": num, - "init": True + "init": True, + "selective": wi.get("selective", False) }) num += 1 @@ -1722,9 +1747,11 @@ def importgame(): for wi in ref["worldInfo"]: vars.worldinfo.append({ "key": wi["keys"], + "keysecondary": wi.get("keysecondary", ""), "content": wi["entry"], "num": num, - "init": True + "init": True, + "selective": wi.get("selective", False) }) num += 1 @@ -1766,9 +1793,11 @@ def importAidgRequest(id): for wi in js["worldInfos"]: vars.worldinfo.append({ "key": wi["keys"], + "keysecondary": wi.get("keysecondary", ""), "content": wi["entry"], "num": num, - "init": True + "init": True, + "selective": wi.get("selective", False) }) num += 1 @@ -1797,9 +1826,11 @@ def wiimportrequest(): for wi in js: vars.worldinfo.append({ "key": wi["keys"], + "keysecondary": wi.get("keysecondary", ""), "content": wi["entry"], "num": num, - "init": True + "init": True, + "selective": wi.get("selective", False) }) num += 1 diff --git a/static/application.js b/static/application.js index 5a01f289..2b9bd2db 100644 --- a/static/application.js +++ b/static/application.js @@ -178,21 +178,51 @@ function addImportLine(ob) { function addWiLine(ob) { if(ob.init) { - wi_menu.append("
\ -
\ - \ - \ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
"); + if(ob.selective){ + wi_menu.append("
\ +
\ + \ + \ + \ +
\ +
\ + \ + \ + \ +
\ +
\ + \ +
\ +
\ + \ + \ +
\ +
"); + } else { + wi_menu.append("
\ +
\ + \ + \ + \ +
\ +
\ + \ + \ + \ +
\ +
\ + \ +
\ +
\ + \ + \ +
\ +
"); + } // Send key value to text input $("#wikey"+ob.num).val(ob.key); + $("#wikeyprimary"+ob.num).val(ob.key); + $("#wikeysecondary"+ob.num).val(ob.keysecondary); // Assign delete event to button $("#btn_wi"+ob.num).on("click", function () { showWiDeleteConfirm(ob.num); @@ -206,11 +236,17 @@ function addWiLine(ob) { \ \
\ - \ + \ + \ + \
\
\ \
\ +
\ + \ + \ +
\ "); // Assign function to expand WI item to button $("#btn_wi"+ob.num).on("click", function () { @@ -224,10 +260,16 @@ function addWiLine(ob) { $("#btn_widel"+ob.num).on("click", function () { socket.send({'cmd': 'widelete', 'data': ob.num}); }); + $("#btn_wiselon"+ob.num).on("click", function () { + enableWiSelective(ob.num); + }); + $("#btn_wiseloff"+ob.num).on("click", function () { + disableWiSelective(ob.num); + }); } function expandWiLine(num) { - show([$("#wikey"+num), $("#wientry"+num)]); + show([$("#wikey"+num), $("#wientry"+num), $("#btn_wiselon"+num)]); $("#btn_wi"+num).html("X"); $("#btn_wi"+num).off(); // Tell server the WI entry was initialized @@ -247,6 +289,20 @@ function hideWiDeleteConfirm(num) { hide([$("#btn_widel"+num), $("#btn_wican"+num)]); } +function enableWiSelective(num) { + hide([$("#btn_wiselon"+num), $("#wikey"+num)]); + // Tell server the WI entry is now selective + socket.send({'cmd': 'wiselon', 'data': num}); + show([$("#wikeyprimary"+num), $("#wikeysecondary"+num), $("#btn_wiseloff"+num)]); +} + +function disableWiSelective(num) { + hide([$("#btn_wiseloff"+num), $("#wikeyprimary"+num), $("#wikeysecondary"+num)]); + // Tell server the WI entry is now non-selective + socket.send({'cmd': 'wiseloff', 'data': num}); + show([$("#btn_wiselon"+num), $("#wikey"+num)]); +} + function highlightImportLine(ref) { $("#popupcontent > div").removeClass("popuplistselected"); ref.addClass("popuplistselected"); @@ -397,9 +453,11 @@ function returnWiList(ar) { var list = []; var i; for(i=0; i input { - height: 100%; background-color: #404040; color: #ffffff; } @@ -686,4 +686,8 @@ action { width: 80%; overflow: hidden; font-size: 12pt; -} \ No newline at end of file +} + +.wiselective > button { + white-space: normal; +}