Skip to content

Commit

Permalink
variable replacement working. Next button without text. example story…
Browse files Browse the repository at this point in the history
… broken into smaller pieces.

Signed-off-by: Sebastian Schmittner <[email protected]>
  • Loading branch information
Echsecutor committed Sep 8, 2024
1 parent aedabbf commit 7dfe049
Show file tree
Hide file tree
Showing 12 changed files with 6,418 additions and 8 deletions.
2,078 changes: 2,078 additions & 0 deletions commons/bootstrap-icons-font/bootstrap-icons.css

Large diffs are not rendered by default.

2,052 changes: 2,052 additions & 0 deletions commons/bootstrap-icons-font/bootstrap-icons.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions commons/bootstrap-icons-font/bootstrap-icons.min.css

Large diffs are not rendered by default.

2,090 changes: 2,090 additions & 0 deletions commons/bootstrap-icons-font/bootstrap-icons.scss

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions editor/code.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cytoscape from "./cytoscape.esm.min.js";
import { toast_alert } from "../toast.js";
import { toast_alert } from "./toast.js";

var story = {};

Expand Down Expand Up @@ -268,8 +268,8 @@ function add__or_remove_media() {
text_editor_load(active_element);
} else {
load_file((content) => {
if (!active_element || !story.sections.includes(active_element)) {
alert("Please section to add media to.");
if (!active_element || !story?.sections?.[active_element.id]) {
alert("Please select section to add media to.");
return;
}

Expand Down
1 change: 0 additions & 1 deletion editor/example_story.json

This file was deleted.

160 changes: 160 additions & 0 deletions editor/example_story.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions viewer/bootstrap-icons-font
25 changes: 23 additions & 2 deletions viewer/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ function start_playing() {
show_ui_components_according_to_state();
}

function replace_variables(text, variables) {
if (!variables || !text) {
return text;
}
var re = text;
for (const key in variables) {
re = re.replaceAll("${" + key + "}", variables[key]);
}
return re;
}

function load_section(id) {
story.state.current_section = id;
if (!story?.sections?.[id]) {
toast_alert("Section ${id} is missing from the story");
return;
Expand All @@ -93,12 +105,15 @@ function load_section(id) {
if (!text) {
toast_alert("This section has no text");
}

text = replace_variables(text, story.state?.variables);

story_text.innerHTML = DOMPurify.sanitize(marked.parse(text));

if (section?.media?.type === "image" && section?.media?.src) {
background_image.src = section.media.src;
background_image.style.display = "inline-block";
}
}

choices_row.innerHTML = "";
if (section?.next) {
Expand All @@ -108,7 +123,13 @@ function load_section(id) {
const button = col.appendChild(document.createElement("button"));
button.className = "btn btn-primary";
button.type = "button";
button.appendChild(document.createTextNode(choice?.text));

if (choice?.text) {
button.appendChild(document.createTextNode(choice.text));
} else {
button.innerHTML = '<i class="bi bi-arrow-right-circle-fill"></i>';
}

button.addEventListener("click", () => {
load_section(choice.next);
});
Expand Down
1 change: 1 addition & 0 deletions viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<title>Story Adventure Viewer</title>
<link href="bootstrap.min.css" rel="stylesheet" />
<script src="bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="bootstrap-icons-font/bootstrap-icons.min.css">
<link href="style.css" rel="stylesheet" />
</head>

Expand Down
7 changes: 5 additions & 2 deletions viewer/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ body {
font-size: x-large;
}

#story_container button {
font-size: x-large;
}

.container {
background-color: black;
opacity: 0.8;
background-color: rgba(0, 0, 0, 0.7);
}

#story_text {
Expand Down

0 comments on commit 7dfe049

Please sign in to comment.