From b1c6aee8d31589bc0f620d7ea8a87be69a4162d3 Mon Sep 17 00:00:00 2001
From: Gnome Ann <>
Date: Tue, 24 Aug 2021 19:02:52 -0400
Subject: [PATCH] Integrate inline chunk editor and Adventure mode with
Javalar's branch
---
aiserver.py | 16 ++++++++++------
static/application.js | 4 +++-
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/aiserver.py b/aiserver.py
index 22fdd64d..a5d7e339 100644
--- a/aiserver.py
+++ b/aiserver.py
@@ -1314,12 +1314,12 @@ def applyoutputformatting(txt):
# Sends the current story content to the Game Screen
#==================================================================#
def refresh_story():
- text_parts = ['', html.escape(vars.prompt), '']
+ text_parts = ['', html.escape(vars.prompt), '']
for idx, item in enumerate(vars.actions, start=1):
item = html.escape(item)
if vars.adventure: # Add special formatting to adventure actions
item = vars.acregex_ui.sub('\\1', item)
- text_parts.extend(('', item, ''))
+ text_parts.extend(('', item, ''))
emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': formatforhtml(''.join(text_parts))}, broadcast=True)
@@ -1344,7 +1344,11 @@ def update_story_chunk(idx: Union[int, Literal['last']]):
# So the chunk index is one more than the corresponding action index.
text = vars.actions[idx - 1]
- chunk_text = f'{formatforhtml(html.escape(text))}'
+ item = html.escape(text)
+ if vars.adventure: # Add special formatting to adventure actions
+ item = vars.acregex_ui.sub('\\1', item)
+
+ chunk_text = f'{formatforhtml(item)}'
emit('from_server', {'cmd': 'updatechunk', 'data': {'index': idx, 'html': chunk_text, 'last': (idx == len(vars.actions))}}, broadcast=True)
@@ -1451,7 +1455,7 @@ def inlineedit(chunk, data):
else:
vars.actions[chunk-1] = data
- refresh_story()
+ update_story_chunk(chunk)
emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True)
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
@@ -1463,12 +1467,12 @@ def inlinedelete(chunk):
# Don't delete prompt
if(chunk == 0):
# Send error message
- refresh_story()
+ update_story_chunk(chunk)
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
else:
del vars.actions[chunk-1]
- refresh_story()
+ remove_story_chunk(chunk)
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
#==================================================================#
diff --git a/static/application.js b/static/application.js
index eb93a51c..b8035582 100644
--- a/static/application.js
+++ b/static/application.js
@@ -848,7 +848,6 @@ $(document).ready(function(){
}
game_text.html(msg.data);
// Make content editable if need be
- $("chunk").attr('tabindex', -1)
$('chunk').attr('contenteditable', allowedit);
hide([$('#curtain')]);
// Scroll to bottom of text
@@ -875,6 +874,8 @@ $(document).ready(function(){
// Append at the end
game_text.append(newChunk);
}
+ newChunk.attr('contenteditable', allowedit);
+ hide([$('#curtain')]);
if(last) {
// Scroll to bottom of text if it's the last element
setTimeout(function () {
@@ -896,6 +897,7 @@ $(document).ready(function(){
chunk.attr('n', newIndex.toString()).attr('id', `n${newIndex}`);
index++;
}
+ hide([$('#curtain')]);
} else if(msg.cmd == "setgamestate") {
// Enable or Disable buttons
if(msg.data == "ready") {