Integrate inline chunk editor and Adventure mode with Javalar's branch
This commit is contained in:
parent
735fc9431b
commit
b1c6aee8d3
16
aiserver.py
16
aiserver.py
|
@ -1314,12 +1314,12 @@ def applyoutputformatting(txt):
|
||||||
# Sends the current story content to the Game Screen
|
# Sends the current story content to the Game Screen
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def refresh_story():
|
def refresh_story():
|
||||||
text_parts = ['<chunk n="0" id="n0">', html.escape(vars.prompt), '</chunk>']
|
text_parts = ['<chunk n="0" id="n0" tabindex="-1">', html.escape(vars.prompt), '</chunk>']
|
||||||
for idx, item in enumerate(vars.actions, start=1):
|
for idx, item in enumerate(vars.actions, start=1):
|
||||||
item = html.escape(item)
|
item = html.escape(item)
|
||||||
if vars.adventure: # Add special formatting to adventure actions
|
if vars.adventure: # Add special formatting to adventure actions
|
||||||
item = vars.acregex_ui.sub('<action>\\1</action>', item)
|
item = vars.acregex_ui.sub('<action>\\1</action>', item)
|
||||||
text_parts.extend(('<chunk n="', str(idx), '" id="n', str(idx), '">', item, '</chunk>'))
|
text_parts.extend(('<chunk n="', str(idx), '" id="n', str(idx), '" tabindex="-1">', item, '</chunk>'))
|
||||||
emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': formatforhtml(''.join(text_parts))}, broadcast=True)
|
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.
|
# So the chunk index is one more than the corresponding action index.
|
||||||
text = vars.actions[idx - 1]
|
text = vars.actions[idx - 1]
|
||||||
|
|
||||||
chunk_text = f'<chunk n="{idx}" id="n{idx}">{formatforhtml(html.escape(text))}</chunk>'
|
item = html.escape(text)
|
||||||
|
if vars.adventure: # Add special formatting to adventure actions
|
||||||
|
item = vars.acregex_ui.sub('<action>\\1</action>', item)
|
||||||
|
|
||||||
|
chunk_text = f'<chunk n="{idx}" id="n{idx}" tabindex="-1">{formatforhtml(item)}</chunk>'
|
||||||
emit('from_server', {'cmd': 'updatechunk', 'data': {'index': idx, 'html': chunk_text, 'last': (idx == len(vars.actions))}}, broadcast=True)
|
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:
|
else:
|
||||||
vars.actions[chunk-1] = data
|
vars.actions[chunk-1] = data
|
||||||
|
|
||||||
refresh_story()
|
update_story_chunk(chunk)
|
||||||
emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True)
|
emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True)
|
||||||
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
||||||
|
|
||||||
|
@ -1463,12 +1467,12 @@ def inlinedelete(chunk):
|
||||||
# Don't delete prompt
|
# Don't delete prompt
|
||||||
if(chunk == 0):
|
if(chunk == 0):
|
||||||
# Send error message
|
# Send error message
|
||||||
refresh_story()
|
update_story_chunk(chunk)
|
||||||
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
|
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
|
||||||
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
||||||
else:
|
else:
|
||||||
del vars.actions[chunk-1]
|
del vars.actions[chunk-1]
|
||||||
refresh_story()
|
remove_story_chunk(chunk)
|
||||||
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
|
|
@ -848,7 +848,6 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
game_text.html(msg.data);
|
game_text.html(msg.data);
|
||||||
// Make content editable if need be
|
// Make content editable if need be
|
||||||
$("chunk").attr('tabindex', -1)
|
|
||||||
$('chunk').attr('contenteditable', allowedit);
|
$('chunk').attr('contenteditable', allowedit);
|
||||||
hide([$('#curtain')]);
|
hide([$('#curtain')]);
|
||||||
// Scroll to bottom of text
|
// Scroll to bottom of text
|
||||||
|
@ -875,6 +874,8 @@ $(document).ready(function(){
|
||||||
// Append at the end
|
// Append at the end
|
||||||
game_text.append(newChunk);
|
game_text.append(newChunk);
|
||||||
}
|
}
|
||||||
|
newChunk.attr('contenteditable', allowedit);
|
||||||
|
hide([$('#curtain')]);
|
||||||
if(last) {
|
if(last) {
|
||||||
// Scroll to bottom of text if it's the last element
|
// Scroll to bottom of text if it's the last element
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -896,6 +897,7 @@ $(document).ready(function(){
|
||||||
chunk.attr('n', newIndex.toString()).attr('id', `n${newIndex}`);
|
chunk.attr('n', newIndex.toString()).attr('id', `n${newIndex}`);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
hide([$('#curtain')]);
|
||||||
} else if(msg.cmd == "setgamestate") {
|
} else if(msg.cmd == "setgamestate") {
|
||||||
// Enable or Disable buttons
|
// Enable or Disable buttons
|
||||||
if(msg.data == "ready") {
|
if(msg.data == "ready") {
|
||||||
|
|
Loading…
Reference in New Issue