Update author's template effect token usage live

This commit is contained in:
somebody 2022-08-11 18:38:29 -05:00
parent c21c1e3dc0
commit 6ac970b1c0
2 changed files with 15 additions and 5 deletions

View File

@ -3634,7 +3634,7 @@ def get_message(msg):
) )
else: else:
if field == "anoteinput": if field == "anoteinput":
unencoded = buildauthorsnote(unencoded) unencoded = buildauthorsnote(unencoded, msg["data"]["anotetemplate"])
tokens_length = len(tokenizer.encode(unencoded)) tokens_length = len(tokenizer.encode(unencoded))
emit( emit(
@ -3972,11 +3972,11 @@ def actionredo():
#==================================================================# #==================================================================#
# #
#==================================================================# #==================================================================#
def buildauthorsnote(authorsnote): def buildauthorsnote(authorsnote, template):
# Build Author's Note if set # Build Author's Note if set
if authorsnote == "": if authorsnote == "":
return "" return ""
return ("\n" + vars.authornotetemplate + "\n").replace("<|>", authorsnote) return ("\n" + template + "\n").replace("<|>", authorsnote)
def calcsubmitbudgetheader(txt, **kwargs): def calcsubmitbudgetheader(txt, **kwargs):
# Scan for WorldInfo matches # Scan for WorldInfo matches
@ -3988,7 +3988,7 @@ def calcsubmitbudgetheader(txt, **kwargs):
else: else:
mem = vars.memory mem = vars.memory
anotetxt = buildauthorsnote(vars.authornote) anotetxt = buildauthorsnote(vars.authornote, vars.authornotetemplate)
return winfo, mem, anotetxt, found_entries return winfo, mem, anotetxt, found_entries

View File

@ -2151,7 +2151,13 @@ function interpolateRGB(color0, color1, t) {
} }
function updateInputBudget(inputElement) { function updateInputBudget(inputElement) {
socket.send({"cmd": "getfieldbudget", "data": {"unencoded": inputElement.value, "field": inputElement.id}}); let data = {"unencoded": inputElement.value, "field": inputElement.id};
if (inputElement.id === "anoteinput") {
data["anotetemplate"] = $("#anotetemplate").val();
}
socket.send({"cmd": "getfieldbudget", "data": data});
} }
function registerTokenCounters() { function registerTokenCounters() {
@ -3430,6 +3436,10 @@ $(document).ready(function(){
if (handled) ev.preventDefault(); if (handled) ev.preventDefault();
}); });
$("#anotetemplate").on("input", function() {
updateInputBudget(anote_input[0]);
})
registerTokenCounters(); registerTokenCounters();
updateInputBudget(input_text[0]); updateInputBudget(input_text[0]);