Make all WI commands use UIDs instead of nums

This commit is contained in:
Gnome Ann 2021-12-31 21:22:51 -05:00
parent ccfafe4f0a
commit b88d49e359
3 changed files with 53 additions and 48 deletions

View File

@ -134,7 +134,7 @@ class vars:
corescript = "default.lua" # Filename of corescript to load
# badwords = [] # Array of str/chr values that should be removed from output
badwordsids = [[13460], [6880], [50256], [42496], [4613], [17414], [22039], [16410], [27], [29], [38430], [37922], [15913], [24618], [28725], [58], [47175], [36937], [26700], [12878], [16471], [37981], [5218], [29795], [13412], [45160], [3693], [49778], [4211], [20598], [36475], [33409], [44167], [32406], [29847], [29342], [42669], [685], [25787], [7359], [3784], [5320], [33994], [33490], [34516], [43734], [17635], [24293], [9959], [23785], [21737], [28401], [18161], [26358], [32509], [1279], [38155], [18189], [26894], [6927], [14610], [23834], [11037], [14631], [26933], [46904], [22330], [25915], [47934], [38214], [1875], [14692], [41832], [13163], [25970], [29565], [44926], [19841], [37250], [49029], [9609], [44438], [16791], [17816], [30109], [41888], [47527], [42924], [23984], [49074], [33717], [31161], [49082], [30138], [31175], [12240], [14804], [7131], [26076], [33250], [3556], [38381], [36338], [32756], [46581], [17912], [49146]] # Tokenized array of badwords used to prevent AI artifacting
deletewi = -1 # Temporary storage for index to delete
deletewi = None # Temporary storage for UID to delete
wirmvwhtsp = False # Whether to remove leading whitespace from WI entries
widepth = 3 # How many historical actions to scan for WI hits
mode = "play" # Whether the interface is in play, memory, or edit mode
@ -3205,19 +3205,24 @@ def addwifolder():
addwiitem(folder_uid=uid)
#==================================================================#
# Move the WI entry with number src so that it immediately precedes
# the WI entry with number dst
# Move the WI entry with UID src so that it immediately precedes
# the WI entry with UID dst
#==================================================================#
def movewiitem(dst, src):
if(vars.worldinfo[src]["folder"] is not None):
for i, e in enumerate(vars.wifolders_u[vars.worldinfo[src]["folder"]]):
if(e is vars.worldinfo[src]):
vars.wifolders_u[vars.worldinfo[src]["folder"]].pop(i)
if(vars.worldinfo_u[src]["folder"] is not None):
for i, e in enumerate(vars.wifolders_u[vars.worldinfo_u[src]["folder"]]):
if(e is vars.worldinfo_u[src]):
vars.wifolders_u[vars.worldinfo_u[src]["folder"]].pop(i)
break
if(vars.worldinfo[dst]["folder"] is not None):
vars.wifolders_u[vars.worldinfo[dst]["folder"]].append(vars.worldinfo[src])
vars.worldinfo[src]["folder"] = vars.worldinfo[dst]["folder"]
vars.worldinfo.insert(dst - (dst >= src), vars.worldinfo.pop(src))
if(vars.worldinfo_u[dst]["folder"] is not None):
vars.wifolders_u[vars.worldinfo_u[dst]["folder"]].append(vars.worldinfo_u[src])
vars.worldinfo_u[src]["folder"] = vars.worldinfo_u[dst]["folder"]
for i, e in enumerate(vars.worldinfo):
if(e is vars.worldinfo_u[src]):
_src = i
elif(e is vars.worldinfo_u[dst]):
_dst = i
vars.worldinfo.insert(_dst - (_dst >= _src), vars.worldinfo.pop(_src))
sendwi()
#==================================================================#
@ -3299,38 +3304,38 @@ def stablesortwi():
#==================================================================#
def commitwi(ar):
for ob in ar:
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"]]["comment"] = ob.get("comment", "")
vars.worldinfo[ob["num"]]["folder"] = ob.get("folder", None)
vars.worldinfo[ob["num"]]["selective"] = ob["selective"]
vars.worldinfo[ob["num"]]["constant"] = ob.get("constant", False)
# Was this a deletion request? If so, remove the requested index
if(vars.deletewi >= 0):
if(vars.worldinfo[vars.deletewi]["folder"] is not None):
for i, e in enumerate(vars.wifolders_u[vars.worldinfo[vars.deletewi]["folder"]]):
if(e is vars.worldinfo[vars.deletewi]):
vars.wifolders_u[vars.worldinfo[vars.deletewi]["folder"]].pop(i)
del vars.worldinfo_u[vars.worldinfo[vars.deletewi]["uid"]]
del vars.worldinfo[vars.deletewi]
# Send the new WI array structure
sendwi()
# And reset deletewi index
vars.deletewi = -1
else:
stablesortwi()
vars.worldinfo_i = [wi for wi in vars.worldinfo if wi["init"]]
ob["uid"] = int(ob["uid"])
vars.worldinfo_u[ob["uid"]]["key"] = ob["key"]
vars.worldinfo_u[ob["uid"]]["keysecondary"] = ob["keysecondary"]
vars.worldinfo_u[ob["uid"]]["content"] = ob["content"]
vars.worldinfo_u[ob["uid"]]["comment"] = ob.get("comment", "")
vars.worldinfo_u[ob["uid"]]["folder"] = ob.get("folder", None)
vars.worldinfo_u[ob["uid"]]["selective"] = ob["selective"]
vars.worldinfo_u[ob["uid"]]["constant"] = ob.get("constant", False)
stablesortwi()
vars.worldinfo_i = [wi for wi in vars.worldinfo if wi["init"]]
#==================================================================#
#
#==================================================================#
def deletewi(num):
if(num < len(vars.worldinfo)):
# Store index of deletion request
vars.deletewi = num
# Get contents of WI HTML inputs
requestwi()
def deletewi(uid):
if(uid in vars.worldinfo_u):
# Store UID of deletion request
vars.deletewi = uid
if(vars.deletewi is not None):
if(vars.worldinfo_u[vars.deletewi]["folder"] is not None):
for i, e in enumerate(vars.wifolders_u[vars.worldinfo_u[vars.deletewi]["folder"]]):
if(e is vars.worldinfo_u[vars.deletewi]):
vars.wifolders_u[vars.worldinfo_u[vars.deletewi]["folder"]].pop(i)
for i, e in enumerate(vars.worldinfo):
if(e is vars.worldinfo_u[vars.deletewi]):
del vars.worldinfo[i]
break
del vars.worldinfo_u[vars.deletewi]
# Send the new WI array structure
sendwi()
# And reset deletewi
vars.deletewi = None
#==================================================================#
#

View File

@ -224,7 +224,7 @@ function addWiLine(ob) {
var current_wifolder_element = ob.folder === null ? $(".wisortable-body:not([folder-uid])").last() : $(".wisortable-body[folder-uid="+ob.folder+"]");
if(ob.init) {
if(ob.selective){
current_wifolder_element.append("<div class=\"wilistitem wilistitem-selective "+(ob.constant ? "wilistitem-constant" : "")+"\" num=\""+ob.num+"\" id=\"wilistitem"+ob.num+"\">\
current_wifolder_element.append("<div class=\"wilistitem wilistitem-selective "+(ob.constant ? "wilistitem-constant" : "")+"\" num=\""+ob.num+"\" uid=\""+ob.uid+"\" id=\"wilistitem"+ob.num+"\">\
<div class=\"wicomment\">\
<textarea class=\"form-control\" placeholder=\"Comment\" id=\"wicomment"+ob.num+"\">"+ob.comment+"</textarea>\
</div>\
@ -262,7 +262,7 @@ function addWiLine(ob) {
</div>\
</div>");
} else {
current_wifolder_element.append("<div class=\"wilistitem "+(ob.constant ? "wilistitem-constant" : "")+"\" num=\""+ob.num+"\" id=\"wilistitem"+ob.num+"\">\
current_wifolder_element.append("<div class=\"wilistitem "+(ob.constant ? "wilistitem-constant" : "")+"\" num=\""+ob.num+"\" uid=\""+ob.uid+"\" id=\"wilistitem"+ob.num+"\">\
<div class=\"wicomment\">\
<textarea class=\"form-control\" placeholder=\"Comment\" id=\"wicomment"+ob.num+"\">"+ob.comment+"</textarea>\
</div>\
@ -311,7 +311,7 @@ function addWiLine(ob) {
});
} else {
// Show WI line item with form fields hidden (uninitialized)
current_wifolder_element.append("<div class=\"wilistitem wilistitem-uninitialized wisortable-excluded\" num=\""+ob.num+"\" id=\"wilistitem"+ob.num+"\">\
current_wifolder_element.append("<div class=\"wilistitem wilistitem-uninitialized wisortable-excluded\" num=\""+ob.num+"\" uid=\""+ob.uid+"\" id=\"wilistitem"+ob.num+"\">\
<div class=\"wicomment\">\
<textarea class=\"form-control hidden\" placeholder=\"Comment\" id=\"wicomment"+ob.num+"\">"+ob.comment+"</textarea>\
</div>\
@ -391,7 +391,7 @@ function addWiLine(ob) {
hideWiDeleteConfirm(ob.num);
});
$("#btn_widel"+ob.num).on("click", function () {
socket.send({'cmd': 'widelete', 'data': ob.num});
socket.send({'cmd': 'widelete', 'data': ob.uid});
});
$("#selective-key-"+ob.num).on("click", function () {
var element = $("#selective-key-"+ob.num);
@ -773,7 +773,7 @@ function returnWiList(ar) {
} else {
folder = parseInt(folder);
}
var ob = {"key": "", "keysecondary": "", "content": "", "comment": "", "folder": null, "num": ar[i], "selective": false, "constant": false};
var ob = {"key": "", "keysecondary": "", "content": "", "comment": "", "folder": null, "uid": parseInt($("#wilistitem"+ar[i]).attr("uid")), "selective": false, "constant": false};
ob.selective = $("#wikeyprimary"+ar[i]).css("display") != "none"
ob.key = ob.selective ? $("#wikeyprimary"+ar[i]).val() : $("#wikey"+ar[i]).val();
ob.keysecondary = $("#wikeysecondary"+ar[i]).val();
@ -1205,16 +1205,16 @@ function sortableOnStop(event, ui) {
// entry was dropped and which WI entry comes immediately after the
// dropped position so that the server can internally move around
// the WI entries
var next_sibling = ui.item.next(".wilistitem").attr("num");
var next_sibling = ui.item.next(".wilistitem").attr("uid");
if(next_sibling === undefined) {
next_sibling = ui.item.next().next().attr("num");
next_sibling = ui.item.next().next().attr("uid");
}
next_sibling = parseInt(next_sibling);
if(Number.isNaN(next_sibling)) {
$(this).sortable("cancel");
return;
}
socket.send({'cmd': 'wimoveitem', 'destination': next_sibling, 'data': parseInt(ui.item.attr("num"))});
socket.send({'cmd': 'wimoveitem', 'destination': next_sibling, 'data': parseInt(ui.item.attr("uid"))});
} else {
// Do the same thing for WI folders
var next_sibling = ui.item.next(".wisortable-container").attr("folder-uid");

View File

@ -17,7 +17,7 @@
<script src="static/bootstrap.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script>
<script src="static/rangy-core.min.js"></script>
<script src="static/application.js?ver=1.16.4t"></script>
<script src="static/application.js?ver=1.16.4u"></script>
</head>
<body>
<input type="file" id="remote-save-select" accept="application/json" style="display:none">