A toy project, but I'm working on a Scrabble clone for my mother to play. There's singleplayer against an AI, and then multiplayer against other people (myself, mostly). Multiplayer needs a server backend with all the game logic which I have programmed in Rust, but there's no reason I can't have the game logic for singleplayer running entirely in the browser.
By compiling my backend code to WASM I basically do that - the client can use either a client-side 'server' or connect to a real server. The UI code itself is unchanged in either case.
I suppose the need in this case is that I have code written in a language other than JS and I want to run it in a browser; inversely I could have written the entire project in JS and hosted my backend server on say Node.
Did you mean single player? Although perhaps I'm just old and thinking about this in a strange way.
And can I clarify.. your scrabble app is web based already right? connecting to a rust web server for the game logic? And you want to embed that server by compiling to wasm? I probably should go read up on how this works.
Not the OP, but most web-based multiplayer games use a server backend to communicate between the multiple players.
> connecting to a rust web server for the game logic? And you want to embed that server by compiling to wasm?
I would assume so, and it being in WASM means they can use the exact same binary code on the server and in the webbrowser.
You could of course do the same thing by writing in Javascript (running in Node on the server or in the browser) but then you are in JS instead of Rust.
i did almost the exact same thing except i wanted the client to enforce the same logic as the server would without having to do api request on every action or having 2 implementations so i just compiled the library code to wasm and that way both the server and the client share the same logic
By compiling my backend code to WASM I basically do that - the client can use either a client-side 'server' or connect to a real server. The UI code itself is unchanged in either case.
I suppose the need in this case is that I have code written in a language other than JS and I want to run it in a browser; inversely I could have written the entire project in JS and hosted my backend server on say Node.