Fix some carrousel and added joystick
This commit is contained in:
parent
556b1d6a4e
commit
7a17455e56
18
app.go
18
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()
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 @@
|
||||
|
||||
<div>
|
||||
<div id="game-detailed-info">
|
||||
|
||||
<p>
|
||||
{selectedGame.Description}
|
||||
</p>
|
||||
</div>
|
||||
<div id="game-media">
|
||||
|
||||
|
||||
4
frontend/wailsjs/go/main/App.d.ts
vendored
4
frontend/wailsjs/go/main/App.d.ts
vendored
@ -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<string>;
|
||||
|
||||
export function LoadGames():Promise<Array<main.Game>>;
|
||||
export function LoadGames():Promise<Array<provider.Game>>;
|
||||
|
||||
export function SelectGame(arg1:string):Promise<void>;
|
||||
|
||||
@ -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"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package lib
|
||||
package inputs
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
123
lib/provider/provider.go
Normal file
123
lib/provider/provider.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user