Skip to content

Commit

Permalink
Merge pull request #16 from SnowdenWintermute/bevy-integration
Browse files Browse the repository at this point in the history
Bevy integration
  • Loading branch information
SnowdenWintermute authored May 2, 2024
2 parents cbe65f8 + 775412e commit d349516
Show file tree
Hide file tree
Showing 311 changed files with 14,364 additions and 4,660 deletions.
4,996 changes: 4,127 additions & 869 deletions Cargo.lock

Large diffs are not rendered by default.

60 changes: 47 additions & 13 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

# Enable max optimizations for dependencies, but not for our code:
[profile.dev.package."*"]
opt-level = 3

[profile.release]
opt-level = 's'
lto = true
codegen-units = 1

[dependencies]
# yew-bevy channel
tokio = { version = "1.36.0", features = ["sync"] }

# yew
yew = {version = "0.21.0", features = ["csr"]}
gloo = "0.10.0"
wasm-bindgen = "0.2.88"
web-sys = {version = "0.3.64", features = ["HtmlInputElement", "DomRect"]}
yew-router = "0.18.0"
# yewdux = "0.9.4"
yewdux = "0.10.0"
common = { path = "../common"}
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -21,15 +33,37 @@ gloo-utils = "0.2.0"
strum = "0.25.0"
strum_macros = "0.25.2"

# [dependencies.web-sys]
# version = "0.3.22"
# features = [
# "BinaryType",
# "Blob",
# "ErrorEvent",
# "FileReader",
# "MessageEvent",
# "ProgressEvent",
# "WebSocket",
# ]

#bevy
bevy_panorbit_camera = "0.16.0"
bevy_mod_billboard = { git = "https://github.com/kulkalkul/bevy_mod_billboard" }
bevy_asset_loader ="0.20"
[dependencies.bevy]
version = "0.13.0"
# Disable the default features if there are any that you do not want
default-features = false
features = [
"animation",
"bevy_asset",
"bevy_audio",
# "bevy_gilrs",
"bevy_scene",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_gltf",
"bevy_render",
"bevy_sprite",
"bevy_text",
"bevy_ui",
# "multi-threaded",
"png",
"hdr",
"vorbis",
# "x11",
"bevy_gizmos",
# "android_shared_stdcxx",
"tonemapping_luts",
"default_font",
"webgl2",
# "bevy_debug_stepping" ,
]
Binary file added client/assets/FiraSans-Regular.ttf
Binary file not shown.
Binary file added client/assets/adventurer.glb
Binary file not shown.
Binary file added client/assets/cube_full.glb
Binary file not shown.
Binary file added client/assets/cube_full_red.glb
Binary file not shown.
Binary file added client/assets/cube_main_skeleton.glb
Binary file not shown.
Binary file added client/assets/dragon_full.glb
Binary file not shown.
Binary file added client/assets/dragon_main_skeleton.glb
Binary file not shown.
Binary file added client/assets/frog_full.glb
Binary file not shown.
Binary file added client/assets/frog_main_skeleton.glb
Binary file not shown.
Binary file added client/assets/main_skeleton.glb
Binary file not shown.
Binary file added client/assets/midieval.glb
Binary file not shown.
Binary file added client/assets/scifi_head.glb
Binary file not shown.
Binary file added client/assets/scifi_legs.glb
Binary file not shown.
Binary file added client/assets/scifi_torso.glb
Binary file not shown.
Binary file added client/assets/skeleton_full.glb
Binary file not shown.
Binary file added client/assets/skeleton_main_skeleton.glb
Binary file not shown.
Binary file added client/assets/skeleton_main_skeletonl.glb
Binary file not shown.
Binary file added client/assets/spear.glb
Binary file not shown.
Binary file added client/assets/sword.glb
Binary file not shown.
Binary file added client/assets/velociraptor_full.glb
Binary file not shown.
Binary file added client/assets/velociraptor_main_skeleton.glb
Binary file not shown.
Binary file added client/assets/wasp_full.glb
Binary file not shown.
Binary file added client/assets/wasp_main_skeleton.glb
Binary file not shown.
Binary file added client/assets/witch_head.glb
Binary file not shown.
Binary file added client/assets/witch_legs.glb
Binary file not shown.
Binary file added client/assets/witch_torso.glb
Binary file not shown.
4 changes: 2 additions & 2 deletions client/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
viewportWidth: 1280,
viewportHeight: 720,
viewportWidth: 1920,
viewportHeight: 1080,
setupNodeEvents(on, config) {
// implement node event listeners here
},
Expand Down
3 changes: 2 additions & 1 deletion client/cypress/e2e/test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe("a test test", () => {

cy.findByRole("button", { name: "Ready" }).click();
// cy.findByText("Open Inventory").click();
// cy.findByText("Ready to explore").click();
cy.findByText("Ready to explore").click();
// cy.findByText(/Open inventory/i).click();

// cy.findByText("Attack").click();
// cy.findByText("Execute").click();
Expand Down
2 changes: 2 additions & 0 deletions client/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="cypress" />
/// <reference types="@testing-library/cypress" />
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
Expand Down
255 changes: 224 additions & 31 deletions client/dist/index.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,233 @@
<!DOCTYPE html><html><head>
<!DOCTYPE html><html class="h-screen w-screen"><head>
<meta charset="utf-8">
<title>Roguelike Racing</title>
<link rel="stylesheet" href="/output-ceff4cd1899f628.css">
<title>Speed Dungeon</title>
<link rel="stylesheet" href="/output-5c3e64f0da7e057c.css" integrity="sha384-W1CLEp+2PC7+IbZBAN0GBGgz2jJeEf6tZwCjqzhAz3RsQZoKdvDIJrI78t/f+be3">
<link rel="stylesheet" href="/scrollbar-8aed7f8b0959eaae.css" integrity="sha384-4iHo6BnYdQ2oksClpcUiRDdAkVLKM7cY5AH/AgDoNghr10TBnAxTS/QkUlWWEJgE">


<link rel="icon" type="image/x-icon" href="./public/favicon.ico">
<base href="/">

<link rel="preload" href="/roguelike-racing-client-d7064d3e279a973c_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/roguelike-racing-client-d7064d3e279a973c.js"></head>
<body>

<script type="module">import init from '/roguelike-racing-client-d7064d3e279a973c.js';init('/roguelike-racing-client-d7064d3e279a973c_bg.wasm');</script><script>(function () {
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
var url = protocol + '//' + window.location.host + '/_trunk/ws';
var poll_interval = 5000;
var reload_upon_connect = () => {
window.setTimeout(
() => {
// when we successfully reconnect, we'll force a
// reload (since we presumably lost connection to
// trunk due to it being killed, so it will have
// rebuilt on restart)
var ws = new WebSocket(url);
ws.onopen = () => window.location.reload();
ws.onclose = reload_upon_connect;
},
poll_interval);
};

var ws = new WebSocket(url);
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
if (msg.reload) {
<link rel="preload" href="/roguelike-racing-client-7e9e609f96953ae6_bg.wasm" crossorigin="anonymous" integrity="sha384-JCtn8jT2OjcufETyqK1UOhQy08cyS5blOHnELXKy1k8bhnixsCbr9C3FWd+6RGvj" as="fetch" type="application/wasm">
<link rel="modulepreload" href="/9e10eb7cb8d5fd08-initializer.mjs" crossorigin="anonymous" integrity="sha384-90hoFGtjwuGt1EEG2O/HLxp6+Sm/SfTW7Pw673Zua3jAg7EVaD/r+JaUr2f3TA39">
<link rel="modulepreload" href="/roguelike-racing-client-7e9e609f96953ae6.js" crossorigin="anonymous" integrity="sha384-YsI/iT5Ot+f7PWmb5OLK1BhVHpviwJvCA6dVBcQH3Nld662yiC/xvKoO3zSEOxOn"></head>

<body class="bg-slate-800 h-screen w-screen">
<div id="yew" class="absolute z-10 pointer-events-none"></div>
<canvas id="bevy" class="!w-screen !h-screen"></canvas>
<!-- loading indicator -->
<div id="loading-indicator" class="absolute z-20 top-1/2 left-1/2 text-lg text-zinc-300 bg-slate-800 border border-slate-400 p-2 transition-opacity duration-1000 -translate-x-1/2 -translate-y-1/2 pointer-events-auto"></div>
<div id="tailwind-class-creator" class="opacity-0 bg-slate-700">

<script type="module">
async function __trunkInitializer(source, initializer) {
if (initializer === undefined) {
return await init(source);
}

return await __trunkInitWithProgress(source, initializer);
}

async function __trunkInitWithProgress(source, initializer) {

const {
onStart, onProgress, onComplete, onSuccess, onFailure
} = initializer;

onStart?.();

const response = fetch(source)
.then((response) => {
const reader = response.body.getReader();
const headers = response.headers;
const status = response.status;
const statusText = response.statusText;

const total = +response.headers.get("Content-Length");
let current = 0;

const stream = new ReadableStream({
start(controller) {
function push() {
reader.read().then(({done, value}) => {
if (done) {
onProgress?.({current: total, total});
controller.close();
return;
}

current += value.byteLength;
onProgress?.({current, total});
controller.enqueue(value);
push();
});
}

push();
},
});

return {
stream, init: {
headers, status, statusText
}
};
})
.then(({stream, init}) =>
new Response(stream, init),
);

return init(response)
.then((value) => {
onComplete?.();
onSuccess?.(value);
return value;
}, (reason) => {
onComplete?.();
onFailure?.(reason);
return reason;
});
}


import init, * as bindings from '/roguelike-racing-client-7e9e609f96953ae6.js';
import initializer from '/9e10eb7cb8d5fd08-initializer.mjs';

await __trunkInitializer('/roguelike-racing-client-7e9e609f96953ae6_bg.wasm', initializer());


window.wasmBindings = bindings;

</script>


</div><script>"use strict";

(function () {

const address = '{{__TRUNK_ADDRESS__}}';
const base = '{{__TRUNK_WS_BASE__}}';
let protocol = '';
protocol =
protocol
? protocol
: window.location.protocol === 'https:'
? 'wss'
: 'ws';
const url = protocol + '://' + address + base + '.well-known/trunk/ws';

class Overlay {
constructor() {
// create an overlay
this._overlay = document.createElement("div");
const style = this._overlay.style;
style.height = "100vh";
style.width = "100vw";
style.position = "fixed";
style.top = "0";
style.left = "0";
style.backgroundColor = "rgba(222, 222, 222, 0.5)";
style.fontFamily = "sans-serif";
// not sure that's the right approach
style.zIndex = "1000000";
style.backdropFilter = "blur(1rem)";

const container = document.createElement("div");
// center it
container.style.position = "absolute";
container.style.top = "30%";
container.style.left = "15%";
container.style.maxWidth = "85%";

this._title = document.createElement("div");
this._title.innerText = "Build failure";
this._title.style.paddingBottom = "2rem";
this._title.style.fontSize = "2.5rem";

this._message = document.createElement("div");
this._message.style.whiteSpace = "pre-wrap";

const icon= document.createElement("div");
icon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#dc3545" viewBox="0 0 16 16"><path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/></svg>';
this._title.prepend(icon);

container.append(this._title, this._message);
this._overlay.append(container);

this._inject();
window.setInterval(() => {
this._inject();
}, 250);
}

set reason(reason) {
this._message.textContent = reason;
}

_inject() {
if (!this._overlay.isConnected) {
// prepend it
document.body?.prepend(this._overlay);
}
}

}

class Client {
constructor(url) {
this.url = url;
this.poll_interval = 5000;
this._overlay = null;
}

start() {
const ws = new WebSocket(this.url);
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
switch (msg.type) {
case "reload":
this.reload();
break;
case "buildFailure":
this.buildFailure(msg.data)
break;
}
};
ws.onclose = this.onclose;
}

onclose() {
window.setTimeout(
() => {
// when we successfully reconnect, we'll force a
// reload (since we presumably lost connection to
// trunk due to it being killed, so it will have
// rebuilt on restart)
const ws = new WebSocket(this.url);
ws.onopen = () => window.location.reload();
ws.onclose = this.onclose;
},
this.poll_interval);
}

reload() {
window.location.reload();
}
};
ws.onclose = reload_upon_connect;

buildFailure({reason}) {
// also log the console
console.error("Build failed:", reason);

console.debug("Overlay", this._overlay);

if (!this._overlay) {
this._overlay = new Overlay();
}
this._overlay.reason = reason;
}
}

new Client(url).start();

})()
</script></body></html>
Loading

0 comments on commit d349516

Please sign in to comment.