Initial Fyrox project
This commit is contained in:
commit
27d327933e
23 changed files with 5633 additions and 0 deletions
12
executor-wasm/Cargo.toml
Normal file
12
executor-wasm/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
[package]
|
||||
name = "executor-wasm"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
fyrox = {workspace = true}
|
||||
red_dragon_pon = { path = "../game" }
|
14
executor-wasm/README.md
Normal file
14
executor-wasm/README.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
## Build instructions
|
||||
|
||||
1. Make sure you have `wasm32-unknown-unknown` target installed in rustup (if not, do: `rustup target add wasm32-unknown-unknown`)
|
||||
2. Make sure you have `wasm-pack` installed (if not, do: `cargo install wasm-pack`)
|
||||
3. To build the executor, do: `wasm-pack build --target web --release`
|
||||
|
||||
## How to run the game on localhost
|
||||
|
||||
1. Make sure you have `basic-http-server` installed (if not, do: `cargo install basic-http-server`).
|
||||
2. Clone assets to the `executor-wasm` directory. Alternatively, clone everything except `Cargo.toml` and `src` directory
|
||||
to the root of your project (`../`).
|
||||
3. Execute `basic-http-server` in `executor-wasm` directory (or in root folder if you you've used alternative path).
|
||||
|
||||
If everything has succeeded, open a web browser at http://localhost:4000/, click "Start" button and your game shoud load.
|
42
executor-wasm/index.html
Normal file
42
executor-wasm/index.html
Normal file
|
@ -0,0 +1,42 @@
|
|||
<!--
|
||||
~ Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
|
||||
~
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ The above copyright notice and this permission notice shall be included in all
|
||||
~ copies or substantial portions of the Software.
|
||||
~
|
||||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
~ SOFTWARE.
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>My Game</title>
|
||||
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<script type="module" defer src="main.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>This page contains WebAssembly and JavaScript content, please enable JavaScript in your browser.</noscript>
|
||||
<main id="main">
|
||||
<button class="button-3d" id="button-start" type="button" role="button">
|
||||
Start
|
||||
</button>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
45
executor-wasm/main.js
Normal file
45
executor-wasm/main.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
const moduleGame = import('./pkg/executor_wasm.js').then(({ default: init, main }) =>
|
||||
init().then(() => main)
|
||||
)
|
||||
const elementTargetButton = document.querySelector('#button-start')
|
||||
const elementMain = document.querySelector('#main')
|
||||
|
||||
const run = async () => {
|
||||
elementTargetButton.removeEventListener('click', run)
|
||||
elementMain.remove()
|
||||
|
||||
const context = new AudioContext()
|
||||
|
||||
if (context.state !== 'running') {
|
||||
await context.resume()
|
||||
}
|
||||
|
||||
return (await moduleGame)()
|
||||
}
|
||||
|
||||
elementTargetButton.addEventListener('click', run, {
|
||||
once: true,
|
||||
passive: true,
|
||||
})
|
45
executor-wasm/src/lib.rs
Normal file
45
executor-wasm/src/lib.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
//! Executor with your game connected to it as a plugin.
|
||||
use fyrox::engine::executor::Executor;
|
||||
use red_dragon_pon::Game;
|
||||
use fyrox::core::wasm_bindgen::{self, prelude::*};
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn error(msg: String);
|
||||
|
||||
type Error;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Error;
|
||||
|
||||
#[wasm_bindgen(structural, method, getter)]
|
||||
fn stack(error: &Error) -> String;
|
||||
}
|
||||
|
||||
fn custom_panic_hook(info: &std::panic::PanicHookInfo) {
|
||||
let mut msg = info.to_string();
|
||||
msg.push_str("\n\nStack:\n\n");
|
||||
let e = Error::new();
|
||||
let stack = e.stack();
|
||||
msg.push_str(&stack);
|
||||
msg.push_str("\n\n");
|
||||
error(msg);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_panic_hook() {
|
||||
use std::sync::Once;
|
||||
static SET_HOOK: Once = Once::new();
|
||||
SET_HOOK.call_once(|| {
|
||||
std::panic::set_hook(Box::new(custom_panic_hook));
|
||||
});
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn main() {
|
||||
set_panic_hook();
|
||||
let mut executor = Executor::new();
|
||||
executor.add_plugin(Game::default());
|
||||
executor.run()
|
||||
}
|
70
executor-wasm/styles.css
Normal file
70
executor-wasm/styles.css
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
/* Need to exclude the scrollbar */
|
||||
min-width: calc(100vw - (100vw - 100%));
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#main {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.button-3d {
|
||||
display: block;
|
||||
position: relative;
|
||||
margin: 0.5em 0;
|
||||
padding: 0.8em 2.2em;
|
||||
cursor: pointer;
|
||||
background: #fff;
|
||||
border: none;
|
||||
border-radius: 0.4em;
|
||||
text-transform: uppercase;
|
||||
font-size: 1.4em;
|
||||
font-family: 'Work Sans', sans-serif;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.04em;
|
||||
mix-blend-mode: color-dodge;
|
||||
perspective: 500px;
|
||||
transform-style: preserve-3d;
|
||||
background-color: yellowgreen;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue