From 5be8d550f1bf8213cd7be582dade80c1ee71517f Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Tue, 2 Aug 2022 04:35:27 +0100
Subject: [PATCH] Set up flit post-processing for HTML

---
 game_core/Trunk.toml |  7 ++++++-
 game_core/flit.toml  | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 game_core/flit.toml

diff --git a/game_core/Trunk.toml b/game_core/Trunk.toml
index 017deba..f9b98e0 100644
--- a/game_core/Trunk.toml
+++ b/game_core/Trunk.toml
@@ -1,2 +1,7 @@
 [build]
-public_url = "./"
\ No newline at end of file
+public_url = "/"
+
+[[hooks]]
+stage = "post_build"
+command = "sh"
+command_arguments = ["-c", "flit -i $TRUNK_STAGING_DIR/index.html -f $TRUNK_SOURCE_DIR/flit.toml --inline"]
\ No newline at end of file
diff --git a/game_core/flit.toml b/game_core/flit.toml
new file mode 100644
index 0000000..69ecdea
--- /dev/null
+++ b/game_core/flit.toml
@@ -0,0 +1,21 @@
+["script[type='module']"]
+action = "wrap"
+template ='''
+<div id="root">
+	<button id="start_game">Start Game</button>
+</div>
+<script>
+document.addEventListener('DOMContentLoaded', () => {
+  	document.getElementById('start_game').addEventListener('click', function() {
+  		let element = document.createElement('{{{TAG}}}');
+  		let attr_string = `{{{ATTR}}}`
+  		attr_string.split(' ').forEach(function(attr) {
+  			let attr_array = attr.split('=');
+  			element.setAttribute(attr_array[0], attr_array[1].slice(1, -1));
+  		});
+  		element.innerHTML = `{{{CONTENT}}}`;
+  		document.body.appendChild(element);
+
+  	});
+});
+</script>'''
\ No newline at end of file
-- 
GitLab