Skip to content

Commit 7158f54

Browse files
committed
fixed bug in set variable action. added full screen and hide text hot keys to viewer
1 parent 6a04de0 commit 7158f54

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stories/*_Chapter_1

commons/common.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,23 @@ export const supported_actions = {
205205
},
206206
};
207207

208-
function set_story_variable(key, value) {
208+
function set_story_variable(story, key, value) {
209209
if (!story.state) {
210210
story.state = {};
211211
}
212212
if (!story.state.variables) {
213213
story.state.variables = {};
214214
}
215215
story.state.variables[key] = value;
216+
console.debug(`Setting ${key} = ${value}`);
216217
}
217218

218219
function set_variable(story, parameters) {
219220
if (!parameters || parameters.length < 2) {
220221
console.log("To few parameters to set variable", parameters);
221222
return;
222223
}
223-
set_story_variable(parameters[0], parameters[1]);
224+
set_story_variable(story, parameters[0], parameters[1]);
224225
}
225226

226227
function add_to_variable(story, parameters) {
@@ -230,6 +231,7 @@ function add_to_variable(story, parameters) {
230231
}
231232

232233
set_story_variable(
234+
story,
233235
parameters[0],
234236
String(Number(parameters[0]) + Number(parameters[1]))
235237
);

commons/storage.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,19 @@ export async function save_story(id, story) {
6666
story: story,
6767
};
6868

69+
// save = put or add
6970
resolve_store_request(
7071
transaction.objectStore(store_name).get(id),
7172
() => {
7273
resolve_store_request(
73-
transaction.objectStore(store_name).put(new_item),
74+
transaction.objectStore(store_name).put(new_item), // if exists -> put to update
7475
resolve,
7576
reject
7677
);
7778
},
7879
() => {
7980
resolve_store_request(
80-
transaction.objectStore(store_name).add(new_item),
81+
transaction.objectStore(store_name).add(new_item), // if not exists -> add
8182
resolve,
8283
reject
8384
);

commons/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function create_element_with_classes_and_attributes(
3232

3333
export function replace_variables(text, variables) {
3434
if (!variables || !text) {
35+
console.debug("Not replacing variables", text, variables);
3536
return text;
3637
}
3738
var re = text;
@@ -51,7 +52,6 @@ export function get_text_from_section(section, variables) {
5152
return replace_variables(text, variables);
5253
}
5354

54-
5555
export const tools_files = {
5656
files: ["LICENSE"],
5757
folders: {

viewer/code.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ const hot_keys = {
1616
description: "back",
1717
action: one_step_back,
1818
},
19+
f: {
20+
description: "toggle full screen",
21+
action: () => {
22+
if (document.fullscreenElement) {
23+
document.exitFullscreen();
24+
return;
25+
}
26+
const element = document.body;
27+
const requestMethod =
28+
element.requestFullScreen ||
29+
element.webkitRequestFullScreen ||
30+
element.mozRequestFullScreen ||
31+
element.msRequestFullScreen;
32+
if (requestMethod) {
33+
// Native full screen.
34+
requestMethod.call(element);
35+
}
36+
},
37+
},
38+
h: {
39+
description: "toggle hide text",
40+
action: () => {
41+
if (story_container.classList.contains("d-none")) {
42+
story_container.classList.remove("d-none");
43+
} else {
44+
story_container.classList.add("d-none");
45+
}
46+
},
47+
},
1948
};
2049

2150
let current_viewer_state = viewer_states.MENU;
@@ -146,7 +175,7 @@ function load_section(id, add_current_section_to_history = true) {
146175
execute_actions(section.script);
147176
}
148177

149-
const text = get_text_from_section(section, story.state?.variables)
178+
const text = get_text_from_section(section, story.state?.variables);
150179

151180
if (!text) {
152181
toast_alert("This section has no text");
@@ -216,7 +245,8 @@ function read_query_params() {
216245
function handle_global_click() {
217246
if (
218247
document.activeElement.nodeName === "INPUT" ||
219-
document.activeElement.nodeName === "BUTTON"
248+
document.activeElement.nodeName === "BUTTON" ||
249+
!story?.state?.current_section
220250
) {
221251
return;
222252
}
@@ -262,13 +292,7 @@ function overwrite_actions() {
262292
return;
263293
}
264294
const user_input = prompt(parameters[1]);
265-
if (!story.state) {
266-
story.state = {};
267-
}
268-
if (!story.state.variables) {
269-
story.state.variables = {};
270-
}
271-
story.state.variables[parameters[0]] = user_input;
295+
supported_actions["SET"].action(st, [parameters[0], user_input]);
272296
};
273297
}
274298

viewer/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ body {
6969
.row {
7070
margin-top: 5px;
7171
}
72+
73+
:link { color: greenyellow; }
74+
:visited { color: greenyellow; }
75+
:link:active, :visited:active { color: greenyellow; }

0 commit comments

Comments
 (0)