Skip to content

Commit

Permalink
remove websocket for now
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Oct 20, 2024
1 parent 72a3224 commit 7553d03
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 90 deletions.
134 changes: 131 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ version = "0.1.0"
edition = "2021"

[dependencies]
async-std = "1.13.0"
bevy-inspector-egui = "0.27.0"
bevy_aseprite_ultra = "0.2.4"
bevy_asset_loader = "0.21.0"
bevy_async_task = "0.2.0"
bevy_ecs_tilemap = "0.14.0"
bevy_light_2d = "0.4.0"
bevy_particle_systems = "0.13.0"
Expand Down Expand Up @@ -60,14 +62,7 @@ features = [

[dependencies.web-sys]
version = "0.3.70"
features = [
"console",
"Window",
"Storage",
"WebSocket",
"MessageEvent",
"ErrorEvent",
]
features = ["console", "Window", "Storage"]

[dependencies.bevy_rapier2d]
version = "0.27.0"
Expand Down
3 changes: 2 additions & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://trunkrs.dev/configuration/
[build]
release = true
minify = "always"
public_url = "./"
dist = "docs"
minify = "always"
wasm_opt = 0
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script integrity=sha384-DXfxbHnmRjXl3uhZSP4S1IWEe3DfX/sHDa2A7iHxmUB6Ag+87PaP8wV2AtDOwHfm src=./restart-audio-context-8127143435824044.js type=module></script><link href=./index-56627a79e0752a1c.css integrity=sha384-m/ivHNojsD/VAvwMMce+fhrN8VxOZuZt5hms1JExuO36KLCDKKRGDtjLXSlnQq0B rel=stylesheet><script nonce="iGEe4s3oX1SQSqG3f7F0nQ==" type=module>import init, * as bindings from './my_bevy_game-a8b691d97a29bb5e.js';
const wasm = await init('./my_bevy_game-a8b691d97a29bb5e_bg.wasm');
<script integrity=sha384-DXfxbHnmRjXl3uhZSP4S1IWEe3DfX/sHDa2A7iHxmUB6Ag+87PaP8wV2AtDOwHfm src=./restart-audio-context-8127143435824044.js type=module></script><link href=./index-56627a79e0752a1c.css integrity=sha384-m/ivHNojsD/VAvwMMce+fhrN8VxOZuZt5hms1JExuO36KLCDKKRGDtjLXSlnQq0B rel=stylesheet><script nonce="HnDuuTQBFLYgiFBRZTbUBQ==" type=module>import init, * as bindings from './my_bevy_game-7d1d0a04ba0fe6f6.js';
const wasm = await init('./my_bevy_game-7d1d0a04ba0fe6f6_bg.wasm');


window.wasmBindings = bindings;


dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));</script><title>Magna Magia 0.1</title><link crossorigin href=./my_bevy_game-a8b691d97a29bb5e.js integrity=sha384-c7UPANyLeFBIKQkwGc9pZehIG28gfpnf9kE/Vdr683uKhr02PXwqPFYoO3SF24xp rel=modulepreload><link as=fetch crossorigin href=./my_bevy_game-a8b691d97a29bb5e_bg.wasm integrity=sha384-j0pisGGUlc2Jc0DvW9XqVuF2CKm1ecxJ3nEL5wBOPpjKkdbeoviN3QE5FQurmU2i rel=preload type=application/wasm></head><body></body></html>
dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));</script><title>Magna Magia 0.1</title><link crossorigin href=./my_bevy_game-7d1d0a04ba0fe6f6.js integrity=sha384-rrdQkJ/5DF+1Zpv18kqf4aAV/vbBrFCrN9AzTxPdYJqdwsC4kICN73mZ35tyKSON rel=modulepreload><link as=fetch crossorigin href=./my_bevy_game-7d1d0a04ba0fe6f6_bg.wasm integrity=sha384-UmLCR8NekVBvOpmFBUqRkR/A1M7oMJRqUpa++55+oRI0YMZTIegQaUtqkhDFwqq/ rel=preload type=application/wasm></head><body></body></html>
1 change: 1 addition & 0 deletions docs/my_bevy_game-7d1d0a04ba0fe6f6.js

Large diffs are not rendered by default.

Binary file not shown.
1 change: 0 additions & 1 deletion docs/my_bevy_game-a8b691d97a29bb5e.js

This file was deleted.

6 changes: 3 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ server.on('connection', (ws, req) => {
});

ws.on('message', (message, isBinary) => {
console.log('received: %s', message);
// console.log('received: %s', message);

const data = message.toString().toUpperCase();
// const data = message.toString();
// ws.send(`Hello, you sent -> ${message.toString().toUpperCase()}`);

server.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data, { binary: isBinary });
client.send(message, { binary: isBinary });
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"start": "node index",
"deploy": "gcloud run deploy magia-server --project=magia --source ."
"deploy": "gcloud run deploy magia-server --project=magia-439208 --region=asia-northeast1 --allow-unauthenticated --max-instances=1 --timeout=60m --source ."
},
"author": "Damien Arrachequesne",
"license": "MIT"
Expand Down
6 changes: 2 additions & 4 deletions server/public/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

(function() {
const socket = new WebSocket("ws://localhost:3000");
const socket = new WebSocket("https://magia-server-38847751193.asia-northeast1.run.app");

socket.onopen = () => {
console.log('Connected to server');
Expand All @@ -10,8 +10,6 @@
};

socket.onmessage = (event) => {
console.log('Message from server', event.data);

socket.send(event.data.toUppserCase());
console.log('Message from server: ', event.data);
};
})();
1 change: 0 additions & 1 deletion src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ mod set;
mod states;
mod tile;
mod wall;
mod websocket;
mod world;
21 changes: 0 additions & 21 deletions src/game/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use super::overlay::*;
use super::player::*;
use super::serialize::*;
use super::states::*;
#[cfg(target_arch = "wasm32")]
use super::websocket::send_to_server;
use super::world::*;
use bevy::asset::{AssetMetaCheck, AssetPlugin};
#[cfg(feature = "debug")]
Expand All @@ -39,21 +37,7 @@ use bevy_rapier2d::prelude::*;
#[cfg(feature = "debug")]
use iyes_perf_ui::PerfUiPlugin;

#[cfg(target_arch = "wasm32")]
use web_sys::console;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsValue;

pub fn run_game() {
#[cfg(target_arch = "wasm32")]
if let Err(err) = send_to_server() {
console::log_1(&JsValue::from_str("Failed to send message to server"));
// console::log_1(
// &JsValue::from_str(&err.as_string().unwrap_or("".to_string())),
// );
}

let mut app = App::new();

app
Expand Down Expand Up @@ -146,11 +130,6 @@ pub fn run_game() {
// https://bevyengine.org/news/bevy-0-14/#state-scoped-entities
.enable_state_scoped_entities::<GameState>();

// bevy_light_2d のプラグインはwasm32向けには対応していません
// https://github.com/jgayfer/bevy_light_2d/issues/5
// https://github.com/jgayfer/bevy_light_2d/issues/6
// https://github.com/jgayfer/bevy_light_2d/pull/7

//
// 以下はデバッグ用のプラグインなど
// 無くてもゲーム事態は動作します
Expand Down
Loading

0 comments on commit 7553d03

Please sign in to comment.