Skip to content

Commit

Permalink
fixed bug in set variable action. added full screen and hide text hot…
Browse files Browse the repository at this point in the history
… keys to viewer
  • Loading branch information
Echsecutor committed Dec 18, 2024
1 parent 6a04de0 commit 7158f54
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stories/*_Chapter_1
6 changes: 4 additions & 2 deletions commons/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,23 @@ export const supported_actions = {
},
};

function set_story_variable(key, value) {
function set_story_variable(story, key, value) {
if (!story.state) {
story.state = {};
}
if (!story.state.variables) {
story.state.variables = {};
}
story.state.variables[key] = value;
console.debug(`Setting ${key} = ${value}`);
}

function set_variable(story, parameters) {
if (!parameters || parameters.length < 2) {
console.log("To few parameters to set variable", parameters);
return;
}
set_story_variable(parameters[0], parameters[1]);
set_story_variable(story, parameters[0], parameters[1]);
}

function add_to_variable(story, parameters) {
Expand All @@ -230,6 +231,7 @@ function add_to_variable(story, parameters) {
}

set_story_variable(
story,
parameters[0],
String(Number(parameters[0]) + Number(parameters[1]))
);
Expand Down
5 changes: 3 additions & 2 deletions commons/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ export async function save_story(id, story) {
story: story,
};

// save = put or add
resolve_store_request(
transaction.objectStore(store_name).get(id),
() => {
resolve_store_request(
transaction.objectStore(store_name).put(new_item),
transaction.objectStore(store_name).put(new_item), // if exists -> put to update
resolve,
reject
);
},
() => {
resolve_store_request(
transaction.objectStore(store_name).add(new_item),
transaction.objectStore(store_name).add(new_item), // if not exists -> add
resolve,
reject
);
Expand Down
2 changes: 1 addition & 1 deletion commons/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function create_element_with_classes_and_attributes(

export function replace_variables(text, variables) {
if (!variables || !text) {
console.debug("Not replacing variables", text, variables);
return text;
}
var re = text;
Expand All @@ -51,7 +52,6 @@ export function get_text_from_section(section, variables) {
return replace_variables(text, variables);
}


export const tools_files = {
files: ["LICENSE"],
folders: {
Expand Down
42 changes: 33 additions & 9 deletions viewer/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ const hot_keys = {
description: "back",
action: one_step_back,
},
f: {
description: "toggle full screen",
action: () => {
if (document.fullscreenElement) {
document.exitFullscreen();
return;
}
const element = document.body;
const requestMethod =
element.requestFullScreen ||
element.webkitRequestFullScreen ||
element.mozRequestFullScreen ||
element.msRequestFullScreen;
if (requestMethod) {
// Native full screen.
requestMethod.call(element);
}
},
},
h: {
description: "toggle hide text",
action: () => {
if (story_container.classList.contains("d-none")) {
story_container.classList.remove("d-none");
} else {
story_container.classList.add("d-none");
}
},
},
};

let current_viewer_state = viewer_states.MENU;
Expand Down Expand Up @@ -146,7 +175,7 @@ function load_section(id, add_current_section_to_history = true) {
execute_actions(section.script);
}

const text = get_text_from_section(section, story.state?.variables)
const text = get_text_from_section(section, story.state?.variables);

if (!text) {
toast_alert("This section has no text");
Expand Down Expand Up @@ -216,7 +245,8 @@ function read_query_params() {
function handle_global_click() {
if (
document.activeElement.nodeName === "INPUT" ||
document.activeElement.nodeName === "BUTTON"
document.activeElement.nodeName === "BUTTON" ||
!story?.state?.current_section
) {
return;
}
Expand Down Expand Up @@ -262,13 +292,7 @@ function overwrite_actions() {
return;
}
const user_input = prompt(parameters[1]);
if (!story.state) {
story.state = {};
}
if (!story.state.variables) {
story.state.variables = {};
}
story.state.variables[parameters[0]] = user_input;
supported_actions["SET"].action(st, [parameters[0], user_input]);
};
}

Expand Down
4 changes: 4 additions & 0 deletions viewer/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ body {
.row {
margin-top: 5px;
}

:link { color: greenyellow; }
:visited { color: greenyellow; }
:link:active, :visited:active { color: greenyellow; }

0 comments on commit 7158f54

Please sign in to comment.