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