generated from schreifuchs/wails-template
add improved controlls
This commit is contained in:
parent
56016d75ab
commit
8d525d27ed
1
app.go
1
app.go
@ -49,7 +49,6 @@ func (a *App) GetGames() (games []model.Game) {
|
|||||||
}
|
}
|
||||||
func (a *App) DeleteGame(g *model.Game) {
|
func (a *App) DeleteGame(g *model.Game) {
|
||||||
a.db.Delete(g)
|
a.db.Delete(g)
|
||||||
|
|
||||||
}
|
}
|
||||||
func (a *App) NewGame() (id uint) {
|
func (a *App) NewGame() (id uint) {
|
||||||
game := model.Game{
|
game := model.Game{
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button, ButtonGroup } from "flowbite-svelte";
|
import { Button } from "flowbite-svelte";
|
||||||
|
|
||||||
let { value = $bindable() }: { value: number } = $props();
|
let { value = $bindable() }: { value: number } = $props();
|
||||||
|
|
||||||
const active: "primary" = "primary";
|
const active: "primary" = "primary";
|
||||||
const passive: "yellow" | "none" = "none";
|
const passive: "none" = "none";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<Button
|
<Button
|
||||||
class="rounded-none rounded-t-lg"
|
class="rounded-none rounded-t-lg dark:text-white"
|
||||||
color={value === 200 ? active : passive}
|
color={value === 200 ? active : passive}
|
||||||
onclick={() => (value = 200)}>200</Button
|
onclick={() => (value = 200)}>200</Button
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
class="rounded-none"
|
class="rounded-none dark:text-white"
|
||||||
color={value === 100 ? active : passive}
|
color={value === 100 ? active : passive}
|
||||||
onclick={() => (value = 100)}
|
onclick={() => (value = 100)}
|
||||||
>
|
>
|
||||||
100</Button
|
100</Button
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
class="rounded-none"
|
class="rounded-none dark:text-white"
|
||||||
color={value === 0 ? active : passive}
|
color={value === 0 ? active : passive}
|
||||||
onclick={() => (value = 0)}>0</Button
|
onclick={() => (value = 0)}>0</Button
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
class="rounded-none"
|
class="rounded-none dark:text-white"
|
||||||
color={value === -100 ? active : passive}
|
color={value === -100 ? active : passive}
|
||||||
onclick={() => (value = -100)}>-100</Button
|
onclick={() => (value = -100)}>-100</Button
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
class="rounded-none rounded-b-lg"
|
class="rounded-none rounded-b-lg dark:text-white"
|
||||||
color={value === -200 ? active : passive}
|
color={value === -200 ? active : passive}
|
||||||
onclick={() => (value = -200)}>-200</Button
|
onclick={() => (value = -200)}>-200</Button
|
||||||
>
|
>
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button, Heading, P, Range } from "flowbite-svelte";
|
import { Button, Heading, P, Range } from "flowbite-svelte";
|
||||||
import { onMount } from "svelte";
|
|
||||||
import { GetGame, SaveStep, UndoFor } from "../../wailsjs/go/main/App";
|
import { GetGame, SaveStep, UndoFor } from "../../wailsjs/go/main/App";
|
||||||
import { model } from "../../wailsjs/go/models";
|
import { model } from "../../wailsjs/go/models";
|
||||||
import { derived } from "svelte/store";
|
import { derived } from "svelte/store";
|
||||||
import TichuSelect from "@/components/TichuSelect.svelte";
|
import TichuSelect from "@/components/TichuSelect.svelte";
|
||||||
import { UndoOutline } from "flowbite-svelte-icons";
|
import { FloppyDiskSolid, UndoOutline } from "flowbite-svelte-icons";
|
||||||
|
|
||||||
let { gameId }: { gameId: number } = $props();
|
let { gameId }: { gameId: number } = $props();
|
||||||
|
|
||||||
@ -30,6 +29,37 @@
|
|||||||
|
|
||||||
return rawPoints;
|
return rawPoints;
|
||||||
});
|
});
|
||||||
|
function save() {
|
||||||
|
let step = new model.Step();
|
||||||
|
step.GameID = gameId;
|
||||||
|
step.PointsTeamA = pointsTeamA;
|
||||||
|
step.AdderTeamA = adderTeamA;
|
||||||
|
step.PointsTeamB = pointsTeamB;
|
||||||
|
step.AdderTeamB = adderTeamB;
|
||||||
|
|
||||||
|
SaveStep(step).then(() => {
|
||||||
|
update();
|
||||||
|
rawPoints = 50;
|
||||||
|
adderTeamA = 0;
|
||||||
|
adderTeamB = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addEventListener("keydown", (event) => {
|
||||||
|
switch (event.key) {
|
||||||
|
case "Enter":
|
||||||
|
save();
|
||||||
|
break;
|
||||||
|
case "z":
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
UndoFor(game).then(update);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "u":
|
||||||
|
UndoFor(game).then(update);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let adderTeamA = $state(0);
|
let adderTeamA = $state(0);
|
||||||
let adderTeamB = $state(0);
|
let adderTeamB = $state(0);
|
||||||
@ -40,7 +70,17 @@
|
|||||||
$effect(update);
|
$effect(update);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-5 m-5">
|
<div
|
||||||
|
class="grid grid-cols-2 gap-5 m-5"
|
||||||
|
onwheel={(e) => {
|
||||||
|
if (e.deltaY > 0 && rawPoints < 130) {
|
||||||
|
rawPoints += 5;
|
||||||
|
}
|
||||||
|
if (e.deltaY < 0 && rawPoints > -30) {
|
||||||
|
rawPoints -= 5;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Heading class="text-center">{game.TeamA}</Heading>
|
<Heading class="text-center">{game.TeamA}</Heading>
|
||||||
<Heading class="text-center">{game.TeamB}</Heading>
|
<Heading class="text-center">{game.TeamB}</Heading>
|
||||||
<div class="col-span-2 flex gap-5 items-center">
|
<div class="col-span-2 flex gap-5 items-center">
|
||||||
@ -57,23 +97,7 @@
|
|||||||
<TichuSelect bind:value={adderTeamA} />
|
<TichuSelect bind:value={adderTeamA} />
|
||||||
<TichuSelect bind:value={adderTeamB} />
|
<TichuSelect bind:value={adderTeamB} />
|
||||||
<div class="col-span-2 flex gap-5 items-center justify-center">
|
<div class="col-span-2 flex gap-5 items-center justify-center">
|
||||||
<Button
|
<Button onclick={save}><FloppyDiskSolid /></Button>
|
||||||
onclick={() => {
|
|
||||||
let step = new model.Step();
|
|
||||||
step.GameID = gameId;
|
|
||||||
step.PointsTeamA = pointsTeamA;
|
|
||||||
step.AdderTeamA = adderTeamA;
|
|
||||||
step.PointsTeamB = pointsTeamB;
|
|
||||||
step.AdderTeamB = adderTeamB;
|
|
||||||
|
|
||||||
SaveStep(step).then(() => {
|
|
||||||
update();
|
|
||||||
rawPoints = 50;
|
|
||||||
adderTeamA = 0;
|
|
||||||
adderTeamB = 0;
|
|
||||||
});
|
|
||||||
}}>Save</Button
|
|
||||||
>
|
|
||||||
<Button color="red" onclick={() => UndoFor(game).then(update)}
|
<Button color="red" onclick={() => UndoFor(game).then(update)}
|
||||||
><UndoOutline /></Button
|
><UndoOutline /></Button
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user