test
This commit is contained in:
parent
b85ca7c3cf
commit
29bcd3cd6b
12
app.go
12
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) {
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
<option value="local">Local (Mock)</option>
|
||||
<option value="remote">Remote (API)</option>
|
||||
<option value="remote-showcase">Showcase</option>
|
||||
<option value="new-model">New Model</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
|
||||
@ -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<Game[]> {
|
||||
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)
|
||||
|
||||
2
frontend/wailsjs/go/main/App.d.ts
vendored
2
frontend/wailsjs/go/main/App.d.ts
vendored
@ -5,7 +5,7 @@ import {provider} from '../models';
|
||||
|
||||
export function LoadGames(arg1:string):Promise<Array<models.Metadata>>;
|
||||
|
||||
export function LoadGamesNewModel():Promise<Array<models.Game>>;
|
||||
export function LoadGamesNewModel(arg1:string):Promise<Array<models.Game>>;
|
||||
|
||||
export function LoadImage(arg1:string,arg2:string):Promise<provider.FileBlob>;
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user