From 7a17455e56450be0776c13913a2b7402238ac957 Mon Sep 17 00:00:00 2001 From: Guillaume Langlois Date: Tue, 7 Jan 2025 19:18:06 -0500 Subject: [PATCH] Fix some carrousel and added joystick --- app.go | 18 ++--- frontend/README.md | 6 ++ frontend/src/App.svelte | 16 ++-- frontend/wailsjs/go/main/App.d.ts | 4 +- frontend/wailsjs/go/models.ts | 4 +- go.mod | 2 +- lib/{ => inputs}/joystick.go | 2 +- lib/provider/provider.go | 123 ++++++++++++++++++++++++++++++ 8 files changed, 151 insertions(+), 24 deletions(-) rename lib/{ => inputs}/joystick.go (98%) create mode 100644 lib/provider/provider.go diff --git a/app.go b/app.go index 8ee29a3..0d0e6f3 100644 --- a/app.go +++ b/app.go @@ -4,7 +4,8 @@ import ( "context" "fmt" - "conjure-os/lib" + "conjure-os/lib/inputs" + "conjure-os/lib/provider" "github.com/wailsapp/wails/v2/pkg/runtime" ) @@ -14,13 +15,6 @@ type App struct { ctx context.Context } -type Game struct { - Title string - Developper string - Year int - Cartridge string -} - // NewApp creates a new App application struct func NewApp() *App { return &App{} @@ -30,7 +24,8 @@ func NewApp() *App { // so we can call the runtime methods func (a *App) startup(ctx context.Context) { a.ctx = ctx - lib.Start() + inputs.Start() + provider.Update() } // Greet returns a greeting for the given name @@ -42,7 +37,6 @@ func (a *App) Greet(name string) string { func (a *App) SelectGame(id string) { } -func (a *App) LoadGames() []Game { - - return []Game{Game{"Soul Shaper", "Conjure", 2024, "https://img.itch.zone/aW1hZ2UvMTkwMzc5MS8xMTgzNzY0Ny5wbmc=/794x1000/Tj3YaD.png"}, Game{"Overdue", "Conjure", 2023, "https://img.itch.zone/aW1hZ2UvMTM2MTI1OS84NjE0MDY4LnBuZw==/794x1000/Y%2B8kqa.png"}} +func (a *App) LoadGames() []provider.Game { + return provider.ObtainConjureGameInfo() } diff --git a/frontend/README.md b/frontend/README.md index a346289..727ce49 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,5 +1,11 @@ + + # Svelte + Vite + +## HOW TO RUN +`wails dev` + This template should help get you started developing with Svelte in Vite. ## Recommended IDE Setup diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index e379306..47fa8e4 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -3,8 +3,6 @@ import { onMount } from 'svelte'; import {LoadGames, SelectGame} from '../wailsjs/go/main/App.js' - let resultText = "Please enter your name below 👇" - let name let games = [] let activeIndex = 0; let currentDeg = 0; @@ -27,7 +25,6 @@ function parse(node) { - var degree = 360/games.length; let i = 0; games.forEach(game => { if(document.getElementById(game.Title) != null) { @@ -35,7 +32,6 @@ document.getElementById(game.Title).style.transform = "rotateY("+40*i+"deg) translateZ(412px)"; } i ++; - }); } @@ -54,13 +50,17 @@ } function switchGame(direction) { + if(activeIndex-direction < 0 || activeIndex-direction >= games.length) + return; + activeIndex -= direction; if(activeIndex > games.length){ - activeIndex = 0; + activeIndex += direction; + return; } - currentDeg = direction *40 * activeIndex; let carrousel = document.getElementById("carousel"); + currentDeg = 40 * activeIndex * -1; carrousel.style.transform = `rotateY(${currentDeg}deg) `;/*carouselnext 40s steps(1000, end) 1";*/ @@ -142,7 +142,9 @@
- +

+ {selectedGame.Description} +

diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 1043618..ca92188 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -1,9 +1,9 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -import {main} from '../models'; +import {provider} from '../models'; export function Greet(arg1:string):Promise; -export function LoadGames():Promise>; +export function LoadGames():Promise>; export function SelectGame(arg1:string):Promise; diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index b8d93de..c1dd05a 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -1,10 +1,11 @@ -export namespace main { +export namespace provider { export class Game { Title: string; Developper: string; Year: number; Cartridge: string; + Description: string; static createFrom(source: any = {}) { return new Game(source); @@ -16,6 +17,7 @@ export namespace main { this.Developper = source["Developper"]; this.Year = source["Year"]; this.Cartridge = source["Cartridge"]; + this.Description = source["Description"]; } } diff --git a/go.mod b/go.mod index 99a8ab2..3d04649 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/fsnotify/fsnotify v1.4.9 github.com/wailsapp/wails v1.16.9 github.com/wailsapp/wails/v2 v2.9.2 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -52,7 +53,6 @@ require ( golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) // replace github.com/wailsapp/wails/v2 v2.9.2 => /Users/guillaumelanglois/go/pkg/mod diff --git a/lib/joystick.go b/lib/inputs/joystick.go similarity index 98% rename from lib/joystick.go rename to lib/inputs/joystick.go index 949e30d..c06a11f 100644 --- a/lib/joystick.go +++ b/lib/inputs/joystick.go @@ -1,4 +1,4 @@ -package lib +package inputs import ( "encoding/binary" diff --git a/lib/provider/provider.go b/lib/provider/provider.go new file mode 100644 index 0000000..0d9b127 --- /dev/null +++ b/lib/provider/provider.go @@ -0,0 +1,123 @@ +package provider + +import ( + "encoding/json" + "fmt" + "io/fs" + "log" + "net/http" + "net/url" + "os" + "strings" + + "gopkg.in/yaml.v3" +) + +type Game struct { + Title string + Developper string + Year int + Cartridge string + Description string +} + +var token string + +const game_path = "/Users/guillaumelanglois/Games/conjure" + +func Update() { + requestURL := fmt.Sprintf("http://localhost:%d", 8080) + login(requestURL) + allGames(requestURL) +} + +type AuthResponse struct { + Token string `json:"token"` +} + +func login(requestURL string) { + client := &http.Client{} + form := url.Values{ + "username": {"test"}, + "password": {"test"}} + req, _ := http.NewRequest("POST", requestURL+"/login", strings.NewReader(form.Encode())) + req.Header.Set("API-Version", "1") + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + res, err := client.Do(req) + check(err) + var auth AuthResponse + err = json.NewDecoder(res.Body).Decode(&auth) + check(err) + token = auth.Token +} + +func allGames(requestURL string) { + + client := &http.Client{} + req, _ := http.NewRequest("GET", requestURL+"/games", nil) + req.Header.Set("Authorization", token) + req.Header.Set("API-Version", "1") + res, err := client.Do(req) + + check(err) + fmt.Println("client: status code: %d\n", res.StatusCode) +} + +func ObtainConjureGameInfo() []Game { + entries, err := os.ReadDir(game_path) + if err != nil { + log.Fatal(err) + } + games := []Game{} + + for _, e := range entries { + if e.IsDir() { + newGames := readFolder(e, game_path) + games = append(newGames, games...) + } + } + + if len(games) > 0 { + fmt.Println("Found Conjure Games: " + string(len(games))) + } else { + fmt.Println("No Conjure games Found") + } + return games +} + +func readFolder(entry fs.DirEntry, path string) []Game { + newPath := path + "/" + entry.Name() + entries, err := os.ReadDir(newPath) + check(err) + + games := []Game{} + + for _, e := range entries { + if e.IsDir() { + games = append(games, readFolder(e, newPath)...) + } else { + filenamesplit := strings.Split(e.Name(), ".") + + if filenamesplit[1] == "conf" && filenamesplit[2] == "yml" { + game := parseGameInfoFromFile(newPath + "/" + e.Name()) + games = append(games, game) + } + } + } + return games +} + +func parseGameInfoFromFile(path string) Game { + data, err := os.ReadFile(path) + check(err) + game := Game{} + err = yaml.Unmarshal(data, &game) + check(err) + return game +} + +func check(e error) { + if e != nil { + panic(e) + } +}