Skip to content

Commit

Permalink
Merge pull request #16 from VICTORVICKIE/url
Browse files Browse the repository at this point in the history
Added: Selected Example to URL Search Param
  • Loading branch information
rexim authored Feb 17, 2024
2 parents 6e74344 + a124b38 commit b4ec056
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
</select>
<canvas id="game"></canvas>
<script>
// TODO: store the current example in the URL
const wasmPaths = {
"tsoding": ["game",],
"core": ["core_basic_window", "core_basic_screen_manager", "core_input_keys", "core_input_mouse_wheel",],
"shapes": ["shapes_colors_palette"]
}
const defaultWasm = Object.values(wasmPaths)[0];

const raylibExampleSelect = document.getElementById("raylib-example-select");

Expand All @@ -65,6 +65,11 @@
let raylibJs = undefined;

function startRaylib(selectedWasm){
var queryParams = new URLSearchParams(window.location.search);
queryParams.set("example", selectedWasm);
history.pushState(null, null, "?"+queryParams.toString());
raylibExampleSelect.value = selectedWasm;

if (isHosted) {
if (raylibJs !== undefined) {
raylibJs.stop();
Expand All @@ -90,7 +95,11 @@
}
}

startRaylib("game");
let queryParams = new URLSearchParams(window.location.search);
const exampleParam = queryParams.get("example") ?? defaultWasm;

if (Object.values(wasmPaths).flat().includes(exampleParam)) startRaylib(exampleParam);
else startRaylib(defaultWasm);
</script>
</body>
</html>

0 comments on commit b4ec056

Please sign in to comment.