Skip to content

Commit

Permalink
minor fixes in actions and variables menu loading. Added action test …
Browse files Browse the repository at this point in the history
…story
  • Loading branch information
Echsecutor committed Nov 20, 2024
1 parent ec2b12b commit 314bf5b
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 1 deletion.
11 changes: 10 additions & 1 deletion commons/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,19 @@ export const supported_actions = {
const choices = story.sections[story.state.current_section].next;
for (const choice of choices) {
if (choice.next == parameters[0]) {
story.sections[story.state.current_section].next = choices.splice(
console.debug(
"Removing choice",
choice,
"at position",
choices.indexOf(choice),
"in",
choices
);
story.sections[story.state.current_section].next.splice(
choices.indexOf(choice),
1
);
return;
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions editor/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ function load_graph() {
load_file((content) => {
story = JSON.parse(content);
redraw_adventure_graph();
load_variables_menu();
});
}

Expand Down Expand Up @@ -659,6 +660,7 @@ function clear_all() {
story = {};
redraw_adventure_graph();
text_editor_hide();
load_variables_menu();
}

function paste_image(event) {
Expand Down
239 changes: 239 additions & 0 deletions stories/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
{
"sections": {
"1": {
"id": "1",
"text_lines": [
"# 1",
"",
"This is a variable/actions test story. Initially no variables are set.",
"",
"",
"```",
"v1=1",
"```",
"",
"- v1=${v1}",
"- v2=${v2}",
"- v3=${v3}",
"- v4=${v4}",
"- v5=${v5}",
"- v6=${v6}"
],
"script": [
{
"action": "SET",
"parameters": [
"v1",
"1"
]
}
],
"next": [
{
"text": "2",
"next": 2
}
]
},
"2": {
"id": "2",
"text_lines": [
"# 2",
"",
"```",
"if(v1){",
" v2=2",
"}",
"",
"if(v6){",
" ADD_CHOICE(4, \"new\")",
"}",
"```",
"",
"- v1=${v1}",
"- v2=${v2}",
"- v3=${v3}",
"- v4=${v4}",
"- v5=${v5}",
"- v6=${v6}"
],
"script": [
{
"action": "IF_SET_DO",
"parameters": [
"v1",
"SET",
"v2",
"2"
]
},
{
"action": "IF_SET_DO",
"parameters": [
"v6",
"ADD_CHOICE",
"4",
"new"
]
}
],
"next": [
{
"text": "3",
"next": 3
}
]
},
"3": {
"id": "3",
"text_lines": [
"# 3",
"",
"```",
"if(v1){",
" if(v2){",
" v3=3",
" }",
"}",
"",
"if(v6){",
" v5=6",
"}",
"",
"if(v5){",
" ADD_CHOICE(5, \"goto 5\")",
"}",
"",
"",
"```",
"",
"",
"",
"- v1=${v1}",
"- v2=${v2}",
"- v3=${v3}",
"- v4=${v4}",
"- v5=${v5}",
"- v6=${v6}"
],
"script": [
{
"action": "IF_SET_DO",
"parameters": [
"v1",
"IF_SET_DO",
"v2",
"SET",
"v3",
"3"
]
},
{
"action": "IF_SET_DO",
"parameters": [
"v6",
"SET",
"v5",
"6"
]
},
{
"action": "IF_SET_DO",
"parameters": [
"v5",
"ADD_CHOICE",
"5",
"goto 5"
]
}
],
"next": [
{
"text": "4",
"next": 4
}
]
},
"4": {
"id": "4",
"text_lines": [
"# 4",
"",
"```",
"if(v3){",
" ADD_CHOICE(1, \"new v1\")",
"}",
"",
"if (! v6){",
" REMOVE_CHOICE(5)",
"}",
"",
"v6=6",
"",
"```",
"",
"- v1=${v1}",
"- v2=${v2}",
"- v3=${v3}",
"- v4=${v4}",
"- v5=${v5}",
"- v6=${v6}"
],
"script": [
{
"action": "IF_SET_DO",
"parameters": [
"v3",
"ADD_CHOICE",
"1",
"new v1"
]
},
{
"action": "IF_NOT_SET_DO",
"parameters": [
"v6",
"REMOVE_CHOICE",
"5"
]
},
{
"action": "SET",
"parameters": [
"v6",
"6"
]
}
],
"next": [
{
"text": "5",
"next": 5
}
]
},
"5": {
"id": "5",
"text_lines": [
"# 5",
"",
"- v1=${v1}",
"- v2=${v2}",
"- v3=${v3}",
"- v4=${v4}",
"- v5=${v5}",
"- v6=${v6}"
]
}
},
"state": {
"variables": {
"v1": "",
"v2": "",
"v3": "",
"v4": "",
"v5": "",
"v6": ""
}
}
}

0 comments on commit 314bf5b

Please sign in to comment.