Fix some carrousel and added joystick

This commit is contained in:
Guillaume Langlois 2025-01-07 19:18:06 -05:00
parent 556b1d6a4e
commit 7a17455e56
8 changed files with 151 additions and 24 deletions

18
app.go
View File

@ -4,7 +4,8 @@ import (
"context" "context"
"fmt" "fmt"
"conjure-os/lib" "conjure-os/lib/inputs"
"conjure-os/lib/provider"
"github.com/wailsapp/wails/v2/pkg/runtime" "github.com/wailsapp/wails/v2/pkg/runtime"
) )
@ -14,13 +15,6 @@ type App struct {
ctx context.Context ctx context.Context
} }
type Game struct {
Title string
Developper string
Year int
Cartridge string
}
// NewApp creates a new App application struct // NewApp creates a new App application struct
func NewApp() *App { func NewApp() *App {
return &App{} return &App{}
@ -30,7 +24,8 @@ func NewApp() *App {
// so we can call the runtime methods // so we can call the runtime methods
func (a *App) startup(ctx context.Context) { func (a *App) startup(ctx context.Context) {
a.ctx = ctx a.ctx = ctx
lib.Start() inputs.Start()
provider.Update()
} }
// Greet returns a greeting for the given name // 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) SelectGame(id string) {
} }
func (a *App) LoadGames() []Game { func (a *App) LoadGames() []provider.Game {
return provider.ObtainConjureGameInfo()
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"}}
} }

View File

@ -1,5 +1,11 @@
# Svelte + Vite # Svelte + Vite
## HOW TO RUN
`wails dev`
This template should help get you started developing with Svelte in Vite. This template should help get you started developing with Svelte in Vite.
## Recommended IDE Setup ## Recommended IDE Setup

View File

@ -3,8 +3,6 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import {LoadGames, SelectGame} from '../wailsjs/go/main/App.js' import {LoadGames, SelectGame} from '../wailsjs/go/main/App.js'
let resultText = "Please enter your name below 👇"
let name
let games = [] let games = []
let activeIndex = 0; let activeIndex = 0;
let currentDeg = 0; let currentDeg = 0;
@ -27,7 +25,6 @@
function parse(node) { function parse(node) {
var degree = 360/games.length;
let i = 0; let i = 0;
games.forEach(game => { games.forEach(game => {
if(document.getElementById(game.Title) != null) { if(document.getElementById(game.Title) != null) {
@ -35,7 +32,6 @@
document.getElementById(game.Title).style.transform = "rotateY("+40*i+"deg) translateZ(412px)"; document.getElementById(game.Title).style.transform = "rotateY("+40*i+"deg) translateZ(412px)";
} }
i ++; i ++;
}); });
} }
@ -54,13 +50,17 @@
} }
function switchGame(direction) { function switchGame(direction) {
if(activeIndex-direction < 0 || activeIndex-direction >= games.length)
return;
activeIndex -= direction; activeIndex -= direction;
if(activeIndex > games.length){ if(activeIndex > games.length){
activeIndex = 0; activeIndex += direction;
return;
} }
currentDeg = direction *40 * activeIndex;
let carrousel = document.getElementById("carousel"); let carrousel = document.getElementById("carousel");
currentDeg = 40 * activeIndex * -1;
carrousel.style.transform = `rotateY(${currentDeg}deg) `;/*carouselnext 40s steps(1000, end) 1";*/ carrousel.style.transform = `rotateY(${currentDeg}deg) `;/*carouselnext 40s steps(1000, end) 1";*/
@ -142,7 +142,9 @@
<div> <div>
<div id="game-detailed-info"> <div id="game-detailed-info">
<p>
{selectedGame.Description}
</p>
</div> </div>
<div id="game-media"> <div id="game-media">

View File

@ -1,9 +1,9 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
import {main} from '../models'; import {provider} from '../models';
export function Greet(arg1:string):Promise<string>; export function Greet(arg1:string):Promise<string>;
export function LoadGames():Promise<Array<main.Game>>; export function LoadGames():Promise<Array<provider.Game>>;
export function SelectGame(arg1:string):Promise<void>; export function SelectGame(arg1:string):Promise<void>;

View File

@ -1,10 +1,11 @@
export namespace main { export namespace provider {
export class Game { export class Game {
Title: string; Title: string;
Developper: string; Developper: string;
Year: number; Year: number;
Cartridge: string; Cartridge: string;
Description: string;
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
return new Game(source); return new Game(source);
@ -16,6 +17,7 @@ export namespace main {
this.Developper = source["Developper"]; this.Developper = source["Developper"];
this.Year = source["Year"]; this.Year = source["Year"];
this.Cartridge = source["Cartridge"]; this.Cartridge = source["Cartridge"];
this.Description = source["Description"];
} }
} }

2
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/wailsapp/wails v1.16.9 github.com/wailsapp/wails v1.16.9
github.com/wailsapp/wails/v2 v2.9.2 github.com/wailsapp/wails/v2 v2.9.2
gopkg.in/yaml.v3 v3.0.1
) )
require ( require (
@ -52,7 +53,6 @@ require (
golang.org/x/net v0.25.0 // indirect golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.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 // replace github.com/wailsapp/wails/v2 v2.9.2 => /Users/guillaumelanglois/go/pkg/mod

View File

@ -1,4 +1,4 @@
package lib package inputs
import ( import (
"encoding/binary" "encoding/binary"

123
lib/provider/provider.go Normal file
View File

@ -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)
}
}