From 29bcd3cd6b478787c2b47b91d9dee41fa5a0f1f8 Mon Sep 17 00:00:00 2001 From: Trit0 Date: Mon, 15 Sep 2025 21:29:56 -0400 Subject: [PATCH] test --- app.go | 12 ++++- frontend/src/components/OptionsModal.vue | 1 + frontend/src/services/game-service.ts | 6 ++- frontend/wailsjs/go/main/App.d.ts | 2 +- frontend/wailsjs/go/main/App.js | 4 +- lib/provider/provider.go | 69 +++++++++++++++++++++++- 6 files changed, 86 insertions(+), 8 deletions(-) diff --git a/app.go b/app.go index 91f039f..9e8262c 100644 --- a/app.go +++ b/app.go @@ -110,8 +110,16 @@ func (a *App) LoadGames(mode string) []models.Metadata { return games } -func (a *App) LoadGamesNewModel() []models.Game { - return []models.Game{} +func (a *App) LoadGamesNewModel(mode string) []models.Game { + mgames := provider.GetConjureGameInfoNew() + + if mode == "remote-showcase" { + mgames = provider.Filter(mgames, func(game models.Game) bool { + return game.Title == "Soul Shaper" || game.Title == "One Pixel Remaning" || game.Title == "Pong" + }) + } + + return mgames } func (a *App) Log(message string) { diff --git a/frontend/src/components/OptionsModal.vue b/frontend/src/components/OptionsModal.vue index 654afab..65b7603 100644 --- a/frontend/src/components/OptionsModal.vue +++ b/frontend/src/components/OptionsModal.vue @@ -10,6 +10,7 @@ + diff --git a/frontend/src/services/game-service.ts b/frontend/src/services/game-service.ts index 5882d53..bb1c1f2 100644 --- a/frontend/src/services/game-service.ts +++ b/frontend/src/services/game-service.ts @@ -1,4 +1,4 @@ -import {LoadGames} from "../../wailsjs/go/main/App"; +import { LoadGames, LoadGamesNewModel } from "../../wailsjs/go/main/App"; import {models} from "../../wailsjs/go/models"; import Metadata = models.Metadata; import Game = models.Game; @@ -100,6 +100,10 @@ export async function fetchGames(): Promise { const source = localStorage.getItem('dataSource') || 'local'; if (source === 'local') return mockGames; + if (source === "new-model") { + return (await LoadGamesNewModel(source)) ?? []; + } + const games = (await LoadGames(source)) ?? []; for (const game of games) { console.log(game) diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 9ef1b79..1e52db7 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -5,7 +5,7 @@ import {provider} from '../models'; export function LoadGames(arg1:string):Promise>; -export function LoadGamesNewModel():Promise>; +export function LoadGamesNewModel(arg1:string):Promise>; export function LoadImage(arg1:string,arg2:string):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 43b9641..19ae215 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -6,8 +6,8 @@ export function LoadGames(arg1) { return window['go']['main']['App']['LoadGames'](arg1); } -export function LoadGamesNewModel() { - return window['go']['main']['App']['LoadGamesNewModel'](); +export function LoadGamesNewModel(arg1) { + return window['go']['main']['App']['LoadGamesNewModel'](arg1); } export function LoadImage(arg1, arg2) { diff --git a/lib/provider/provider.go b/lib/provider/provider.go index 70883c6..543a78b 100644 --- a/lib/provider/provider.go +++ b/lib/provider/provider.go @@ -217,7 +217,66 @@ func GetConjureGameInfo() []models.Metadata { fmt.Println("Contents of metadata.txt:") metadata, err := io.ReadAll(rc) check(err) - game := parseGameInfo([]byte(escapeBackslashes(string(metadata)))) + game := parseGameInfoOld([]byte(escapeBackslashes(string(metadata)))) + fmt.Println(game.ThumbnailPath) + games = append(games, game) + } + } + } + } + + if len(games) > 0 { + fmt.Println("Found Conjure Games: ", len(games)) + } else { + fmt.Println("No Conjure games found") + } + return games +} + +func GetConjureGameInfoNew() []models.Game { + gamePath := config.GetDefaultConjureGamesDirectory() + + fmt.Println("Loading games from path " + gamePath + "....") + var games []models.Game + + entries, err := os.ReadDir(gamePath) + if err != nil { + return games + } + + for _, e := range entries { + if e.IsDir() { + continue + } else if filepath.Ext(e.Name()) == ".conj" { + conjPath := filepath.Join(gamePath, e.Name()) + conjBase := strings.TrimSuffix(conjPath, ".conj") + + // Check if the destination folder already exists + if _, err := os.Stat(conjBase); os.IsNotExist(err) { + err = extractZipToSiblingFolder(conjPath) + check(err) + } + + // Now read metadata from the extracted directory + entries, err := os.ReadDir(conjBase) + check(err) + + fmt.Println("Contents of", conjPath) + for _, f := range entries { + if f.Name() == "metadata.txt" { + rc, err := os.Open(filepath.Join(conjBase, f.Name())) + check(err) + defer rc.Close() + + fmt.Println("Contents of metadata.txt:") + metadata, err := io.ReadAll(rc) + check(err) + game, err := parseGameInfo([]byte(escapeBackslashes(string(metadata)))) + + if err != nil { + continue + } + fmt.Println(game.ThumbnailPath) games = append(games, game) } @@ -261,13 +320,19 @@ func printIndentedPath(path string) { } } -func parseGameInfo(data []byte) models.Metadata { +func parseGameInfoOld(data []byte) models.Metadata { game := models.Metadata{} err := yaml.Unmarshal(data, &game) check(err) return game } +func parseGameInfo(data []byte) (models.Game, error) { + game := models.Game{} + err := yaml.Unmarshal(data, &game) + return game, err +} + func check(e error) { if e != nil { panic(e)