all two controllers and no extract every time
This commit is contained in:
parent
5c7c429c70
commit
2872bd6220
2
app.go
2
app.go
@ -16,7 +16,7 @@ import (
|
||||
var (
|
||||
games []models.Game
|
||||
lastEmitTimestamp = time.Now().Add(-10 * time.Second)
|
||||
emitInterval = 300 * time.Millisecond
|
||||
emitInterval = 150 * time.Millisecond
|
||||
gameIsOpen = false
|
||||
)
|
||||
|
||||
|
||||
@ -46,9 +46,7 @@ import { storeToRefs } from "pinia";
|
||||
import { KeyboardManager } from "./utils/keyboard-manager";
|
||||
|
||||
const store = useAppStore();
|
||||
const { selectedTag, selectedGame, tags, games, transitionDirection, qrLink, gameIsStarting } = storeToRefs(store);
|
||||
|
||||
const optionsOpen = ref(false);
|
||||
const { selectedTag, selectedGame, tags, games, transitionDirection, qrLink, gameIsStarting, optionsOpen } = storeToRefs(store);
|
||||
|
||||
onMounted(async () => {
|
||||
games.value = await fetchGames();
|
||||
|
||||
@ -10,8 +10,9 @@ export const useAppStore = defineStore('app', {
|
||||
selectedTag: null as string | null,
|
||||
transitionDirection: 'down' as 'up' | 'down',
|
||||
selectedGame: null as Game | null,
|
||||
selectedGameIndex: 0,
|
||||
selectedGameIndex: -1,
|
||||
qrLink: '' as string,
|
||||
optionsOpen: false as boolean,
|
||||
gameIsStarting: false as boolean
|
||||
}),
|
||||
getters: {
|
||||
@ -42,17 +43,20 @@ export const useAppStore = defineStore('app', {
|
||||
this.selectedGameIndex = index;
|
||||
this.selectedGame = games[index];
|
||||
}
|
||||
else {
|
||||
this.selectedGameIndex = -1;
|
||||
this.selectedGame = null;
|
||||
}
|
||||
},
|
||||
selectTag(tag: string) {
|
||||
this.selectedTag = tag;
|
||||
this.selectedGameIndex = 0;
|
||||
this.selectedGame = this.filteredGames[0] ?? null;
|
||||
this.selectGame(this.selectedGameIndex);
|
||||
},
|
||||
showQr(link: string) {
|
||||
this.qrLink = link;
|
||||
},
|
||||
async startSelectedGame() {
|
||||
if (this.selectedGame) {
|
||||
if (this.selectedGame && !this.gameIsStarting) {
|
||||
this.gameIsStarting = true;
|
||||
await StartGame(this.selectedGame.Id);
|
||||
this.gameIsStarting = false;
|
||||
|
||||
@ -23,6 +23,7 @@ export class CarouselKeyContext extends KeyContext {
|
||||
super.onKeyLeft();
|
||||
if (this.store.selectedGameIndex === 0) {
|
||||
KeyboardManager.switchContext("sidebar");
|
||||
this.store.selectGame(-1);
|
||||
}
|
||||
else {
|
||||
this.store.moveGameLeft();
|
||||
@ -31,6 +32,8 @@ export class CarouselKeyContext extends KeyContext {
|
||||
|
||||
protected onEscape() {
|
||||
super.onEscape();
|
||||
this.store.optionsOpen = true;
|
||||
KeyboardManager.switchContext('options');
|
||||
}
|
||||
|
||||
protected onEnter() {
|
||||
|
||||
@ -46,12 +46,12 @@ export abstract class KeyContext {
|
||||
this.onKeyDown()
|
||||
}
|
||||
|
||||
if ((state.buttons & 0x02) !== 0) {
|
||||
if ((state.buttons & 0x04) !== 0) {
|
||||
this.onEnter()
|
||||
}
|
||||
|
||||
// TODO should be 0x01 when the power button will work
|
||||
if ((state.buttons & 0x04) !== 0) {
|
||||
if ((state.buttons & 0x02) !== 0) {
|
||||
this.onEscape()
|
||||
}
|
||||
}
|
||||
|
||||
13
frontend/src/utils/key-contexts/options-key-context.ts
Normal file
13
frontend/src/utils/key-contexts/options-key-context.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { KeyboardManager } from "../keyboard-manager";
|
||||
import { ModalKeyContext } from "./modal-key-context";
|
||||
|
||||
export class OptionsKeyContext extends ModalKeyContext {
|
||||
public name: string = "OptionsKeyContext";
|
||||
|
||||
protected override onEscape(): void {
|
||||
super.onEscape();
|
||||
this.store.optionsOpen = false;
|
||||
KeyboardManager.switchContext('carousel');
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,15 +1,17 @@
|
||||
import { ControllerState } from "../models/controller-state";
|
||||
import { CarouselKeyContext } from "./key-contexts/carousel-key-context";
|
||||
import { KeyContext } from "./key-contexts/key-context";
|
||||
import { OptionsKeyContext } from "./key-contexts/options-key-context";
|
||||
import { SidebarKeyContext } from "./key-contexts/sidebar-key-context";
|
||||
|
||||
export class KeyboardManager {
|
||||
private static current?: KeyContext;
|
||||
|
||||
static switchContext(name: 'sidebar' | 'carousel') {
|
||||
static switchContext(name: 'sidebar' | 'carousel' | 'options') {
|
||||
console.log("Switching context to " + name);
|
||||
if (name === 'sidebar') this.current = new SidebarKeyContext();
|
||||
else this.current = new CarouselKeyContext();
|
||||
else if (name === 'carousel') this.current = new CarouselKeyContext();
|
||||
else if (name === 'options') this.current = new OptionsKeyContext();
|
||||
}
|
||||
|
||||
static handle(event: KeyboardEvent) {
|
||||
|
||||
@ -138,8 +138,9 @@ func Start(onStateChange func(ControllerState)) {
|
||||
|
||||
state.Id = i
|
||||
|
||||
if state.Buttons != 0 || state.Joystick.X != 127 || state.Joystick.Y != 127 {
|
||||
fmt.Printf("State changed on device %d\n", i)
|
||||
// TODO Samuel please fix help me
|
||||
if (state.Buttons != 0 || state.Joystick.X != 127 || state.Joystick.Y != 127) && !(state.Id == 0 && state.Buttons == 128 && state.Joystick.X != 127 && state.Joystick.Y != 127) {
|
||||
// fmt.Printf("Id: %d - %d buttons ", state.Id, state.Buttons)
|
||||
onStateChange(*state)
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +168,12 @@ func ExtractGame(game models.Game) string {
|
||||
check(err)
|
||||
}
|
||||
gamePath := filepath.Join(config.GetDefaultConjureGamesDirectory(), game.Id)
|
||||
|
||||
_, err = os.Stat(filepath.Join(gamePath, game.Files))
|
||||
if err == nil {
|
||||
return filepath.Join(gamePath, game.Files)
|
||||
}
|
||||
|
||||
err = extractZipsInFolder(gamePath)
|
||||
check(err)
|
||||
gamePath = filepath.Join(gamePath, game.Files)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user