-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: Made the game playable from the server
Now the server has an HTML page (the website) which adds the ability to play the game from the website, no need to download anything. Also migrated the WS lib to one that compiles to WASM as if not I was not able to run the game on the browser.
- Loading branch information
Showing
30 changed files
with
1,101 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//go:build js && wasm | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"syscall/js" | ||
|
||
"github.com/xescugc/go-flux" | ||
"github.com/xescugc/ltw/client" | ||
"github.com/xescugc/ltw/inputer" | ||
"github.com/xescugc/ltw/store" | ||
) | ||
|
||
func main() { | ||
js.Global().Set("new_client", NewClient()) | ||
select {} | ||
} | ||
|
||
func NewClient() js.Func { | ||
return js.FuncOf(func(this js.Value, args []js.Value) any { | ||
if len(args) != 2 || (args[0].String() == "" || args[1].String() == "") { | ||
return fmt.Errorf("requires 2 parameters: room and name") | ||
} | ||
var ( | ||
err error | ||
room = args[0].String() | ||
name = args[1].String() | ||
hostURL = "localhost:5555" | ||
screenW = 288 | ||
screenH = 240 | ||
) | ||
|
||
d := flux.NewDispatcher() | ||
ad := client.NewActionDispatcher(d) | ||
|
||
s := store.NewStore(d) | ||
|
||
g := &client.Game{ | ||
Store: s, | ||
} | ||
|
||
i := inputer.NewEbiten() | ||
|
||
// TODO: Change this to pass the specific store needed instead of all the game object | ||
cs := client.NewCameraStore(d, s, screenW, screenH) | ||
g.Camera = cs | ||
g.Units, err = client.NewUnits(g) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize Units: %w", err) | ||
} | ||
|
||
g.Towers, err = client.NewTowers(g) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize Towers: %w", err) | ||
} | ||
|
||
g.HUD, err = client.NewHUDStore(d, i, g) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize HUDStore: %w", err) | ||
} | ||
|
||
l, err := client.NewLobbyStore(d, i, s, cs) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize LobbyStore: %w", err) | ||
} | ||
rs := client.NewRouterStore(d, g, l) | ||
|
||
ctx := context.Background() | ||
// We need to run this in a goroutine so when it's compiled to WASM | ||
// it does not block the main thread https://github.com/golang/go/issues/41310 | ||
go func() { | ||
err = client.New(ctx, ad, rs, client.Options{ | ||
HostURL: hostURL, | ||
Room: room, | ||
Name: name, | ||
ScreenW: screenW, | ||
ScreenH: screenH, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.