diff --git a/app.go b/app.go
index 3df4052..a240027 100644
--- a/app.go
+++ b/app.go
@@ -3,19 +3,21 @@ package main
import (
"context"
"fmt"
+ "tichu-counter/model"
- "github.com/gen2brain/beeep"
+ "gorm.io/gorm"
)
// App struct
type App struct {
ctx context.Context
+ db *gorm.DB
}
// NewApp creates a new App application struct
-func NewApp() *App {
+func NewApp(db *gorm.DB) *App {
- return &App{}
+ return &App{db: db}
}
// startup is called when the app starts. The context is saved
@@ -23,13 +25,36 @@ func NewApp() *App {
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
- err := beeep.Notify("Hello", "World", "")
- if err != nil {
- fmt.Println(err)
- }
}
// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
}
+
+func (a *App) GetLastGameID() uint {
+ var g model.Game
+ a.db.Order("updated_at DESC").First(&g)
+ return g.ID
+}
+
+func (a *App) GetGame(id uint) (game model.Game) {
+ a.db.Preload("Steps").First(&game, id)
+ game.SumPoints()
+ return
+}
+func (a *App) GetGames() (games []model.Game) {
+ a.db.Find(&games)
+ return
+}
+func (a *App) NewGame() (id uint) {
+ game := model.Game{
+ Steps: []model.Step{},
+ }
+ a.db.Save(&game)
+ return game.ID
+}
+
+func (a *App) SaveStep(s *model.Step) {
+ a.db.Save(s)
+}
diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte
index ee43d0e..6ac2c7f 100644
--- a/frontend/src/App.svelte
+++ b/frontend/src/App.svelte
@@ -1,15 +1,34 @@
-
+
+ {#each games as g}
+ GetGame(g.ID).then((g) => (game = g))}
+ >{g.CreatedAt}
+ {/each}
+
+
+ NewGame().then((id) =>
+ GetGame(id).then((g) => {
+ game = g;
+ update();
+ }),
+ )}>New Game
+
-
-
-
+
+ {#if game !== null}
+
+ {:else}
+ Please select a game
+ {/if}
+
+
+
diff --git a/frontend/src/components/TichuSelect.svelte b/frontend/src/components/TichuSelect.svelte
new file mode 100644
index 0000000..780b815
--- /dev/null
+++ b/frontend/src/components/TichuSelect.svelte
@@ -0,0 +1,38 @@
+
+
+
+ (value = 200)}>200
+ (value = 100)}
+ >
+ 100
+ (value = 0)}>0
+ (value = -100)}>-100
+ (value = -200)}>-200
+
diff --git a/frontend/src/routes/Game.svelte b/frontend/src/routes/Game.svelte
new file mode 100644
index 0000000..e585009
--- /dev/null
+++ b/frontend/src/routes/Game.svelte
@@ -0,0 +1,77 @@
+
+
+
+
{game.TeamA}
+
{game.TeamB}
+
+
{pointsTeamA}
+
+
{pointsTeamB}
+
+
+
+
+ {
+ 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
+
+
diff --git a/frontend/src/routes/Thing.svelte b/frontend/src/routes/Thing.svelte
deleted file mode 100644
index ac128f3..0000000
--- a/frontend/src/routes/Thing.svelte
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
- {thing.Name}
-
-
diff --git a/frontend/src/routes/Things.svelte b/frontend/src/routes/Things.svelte
deleted file mode 100644
index a8568d6..0000000
--- a/frontend/src/routes/Things.svelte
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-
-
-
- ID
- Name
- View
- Delete
-
-
- {#each thingsList as t}
-
-
- {t.ID}
-
-
-
- {t.Name}
-
-
-
- navigate(`/things/${t.ID}`)}>View
-
-
-
- DeleteThing(t.ID).then(update)}>Delete
-
-
- {/each}
-
-
diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts
index 02a3bb9..4b88a25 100755
--- a/frontend/wailsjs/go/main/App.d.ts
+++ b/frontend/wailsjs/go/main/App.d.ts
@@ -1,4 +1,15 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
+import {model} from '../models';
+
+export function GetGame(arg1:number):Promise;
+
+export function GetGames():Promise>;
+
+export function GetLastGameID():Promise;
export function Greet(arg1:string):Promise;
+
+export function NewGame():Promise;
+
+export function SaveStep(arg1:model.Step):Promise;
diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js
index c71ae77..a4a5595 100755
--- a/frontend/wailsjs/go/main/App.js
+++ b/frontend/wailsjs/go/main/App.js
@@ -2,6 +2,26 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
+export function GetGame(arg1) {
+ return window['go']['main']['App']['GetGame'](arg1);
+}
+
+export function GetGames() {
+ return window['go']['main']['App']['GetGames']();
+}
+
+export function GetLastGameID() {
+ return window['go']['main']['App']['GetLastGameID']();
+}
+
export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1);
}
+
+export function NewGame() {
+ return window['go']['main']['App']['NewGame']();
+}
+
+export function SaveStep(arg1) {
+ return window['go']['main']['App']['SaveStep'](arg1);
+}
diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts
index 0da5b89..86addb0 100755
--- a/frontend/wailsjs/go/models.ts
+++ b/frontend/wailsjs/go/models.ts
@@ -1,18 +1,100 @@
export namespace model {
- export class Thing {
+ export class Step {
ID: number;
- Name: string;
+ // Go type: time
+ CreatedAt: any;
+ // Go type: time
+ UpdatedAt: any;
+ // Go type: gorm
+ DeletedAt: any;
+ GameID: number;
+ Game: Game;
+ PointsTeamA: number;
+ AdderTeamA: number;
+ PointsTeamB: number;
+ AdderTeamB: number;
static createFrom(source: any = {}) {
- return new Thing(source);
+ return new Step(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
- this.Name = source["Name"];
+ this.CreatedAt = this.convertValues(source["CreatedAt"], null);
+ this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
+ this.DeletedAt = this.convertValues(source["DeletedAt"], null);
+ this.GameID = source["GameID"];
+ this.Game = this.convertValues(source["Game"], Game);
+ this.PointsTeamA = source["PointsTeamA"];
+ this.AdderTeamA = source["AdderTeamA"];
+ this.PointsTeamB = source["PointsTeamB"];
+ this.AdderTeamB = source["AdderTeamB"];
}
+
+ convertValues(a: any, classs: any, asMap: boolean = false): any {
+ if (!a) {
+ return a;
+ }
+ if (a.slice && a.map) {
+ return (a as any[]).map(elem => this.convertValues(elem, classs));
+ } else if ("object" === typeof a) {
+ if (asMap) {
+ for (const key of Object.keys(a)) {
+ a[key] = new classs(a[key]);
+ }
+ return a;
+ }
+ return new classs(a);
+ }
+ return a;
+ }
+ }
+ export class Game {
+ ID: number;
+ // Go type: time
+ CreatedAt: any;
+ // Go type: time
+ UpdatedAt: any;
+ // Go type: gorm
+ DeletedAt: any;
+ TeamA: number;
+ TeamB: number;
+ Steps: Step[];
+
+ static createFrom(source: any = {}) {
+ return new Game(source);
+ }
+
+ constructor(source: any = {}) {
+ if ('string' === typeof source) source = JSON.parse(source);
+ this.ID = source["ID"];
+ this.CreatedAt = this.convertValues(source["CreatedAt"], null);
+ this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
+ this.DeletedAt = this.convertValues(source["DeletedAt"], null);
+ this.TeamA = source["TeamA"];
+ this.TeamB = source["TeamB"];
+ this.Steps = this.convertValues(source["Steps"], Step);
+ }
+
+ convertValues(a: any, classs: any, asMap: boolean = false): any {
+ if (!a) {
+ return a;
+ }
+ if (a.slice && a.map) {
+ return (a as any[]).map(elem => this.convertValues(elem, classs));
+ } else if ("object" === typeof a) {
+ if (asMap) {
+ for (const key of Object.keys(a)) {
+ a[key] = new classs(a[key]);
+ }
+ return a;
+ }
+ return new classs(a);
+ }
+ return a;
+ }
}
}
diff --git a/frontend/wailsjs/go/things/Service.d.ts b/frontend/wailsjs/go/things/Service.d.ts
deleted file mode 100755
index cda156b..0000000
--- a/frontend/wailsjs/go/things/Service.d.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
-// This file is automatically generated. DO NOT EDIT
-import {model} from '../models';
-
-export function DeleteThing(arg1:number):Promise;
-
-export function GetThings():Promise>;
-
-export function NewThing(arg1:string):Promise;
diff --git a/frontend/wailsjs/go/things/Service.js b/frontend/wailsjs/go/things/Service.js
deleted file mode 100755
index 1d5ee94..0000000
--- a/frontend/wailsjs/go/things/Service.js
+++ /dev/null
@@ -1,15 +0,0 @@
-// @ts-check
-// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
-// This file is automatically generated. DO NOT EDIT
-
-export function DeleteThing(arg1) {
- return window['go']['things']['Service']['DeleteThing'](arg1);
-}
-
-export function GetThings() {
- return window['go']['things']['Service']['GetThings']();
-}
-
-export function NewThing(arg1) {
- return window['go']['things']['Service']['NewThing'](arg1);
-}
diff --git a/go.mod b/go.mod
index 2d47b1d..2da0632 100644
--- a/go.mod
+++ b/go.mod
@@ -1,9 +1,8 @@
-module wails-template
+module tichu-counter
go 1.24.0
require (
- github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
github.com/wailsapp/wails/v2 v2.10.1
gorm.io/driver/sqlite v1.5.7
gorm.io/gorm v1.25.12
@@ -12,7 +11,6 @@ require (
require (
github.com/bep/debounce v1.2.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
- github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
@@ -27,12 +25,10 @@ require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
- github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/samber/lo v1.49.1 // indirect
- github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
github.com/tkrajina/go-reflector v0.5.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
diff --git a/go.sum b/go.sum
index c4258e2..b30eb6f 100644
--- a/go.sum
+++ b/go.sum
@@ -2,12 +2,8 @@ github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=
-github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
-github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
-github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -41,8 +37,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
-github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
-github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -56,8 +50,6 @@ github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
-github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
diff --git a/main.go b/main.go
index d937fb4..84c3b25 100644
--- a/main.go
+++ b/main.go
@@ -2,8 +2,7 @@ package main
import (
"embed"
- "wails-template/model"
- "wails-template/things"
+ "tichu-counter/model"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
@@ -15,13 +14,12 @@ var assets embed.FS
func main() {
// Create an instance of the app structure
- app := NewApp()
db := model.InitDB()
- things := &things.Service{DB: db}
+ app := NewApp(db)
// Create application with options
err := wails.Run(&options.App{
- Title: "wails-template",
+ Title: "tichu-counter",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{
@@ -31,7 +29,6 @@ func main() {
OnStartup: app.startup,
Bind: []interface{}{
app,
- things,
},
})
diff --git a/model/model.go b/model/model.go
index 140bddf..c9afd64 100644
--- a/model/model.go
+++ b/model/model.go
@@ -9,9 +9,33 @@ import (
"gorm.io/gorm"
)
-type Thing struct {
- ID int
- Name string
+type Game struct {
+ gorm.Model
+ TeamA int `gorm:"-"`
+ TeamB int `gorm:"-"`
+
+ Steps []Step `gorm:"foreignKey:GameID"`
+}
+
+func (g *Game) SumPoints() {
+ g.TeamA = 0
+ g.TeamB = 0
+
+ for _, s := range g.Steps {
+ g.TeamA += s.PointsTeamA + s.AdderTeamA
+ g.TeamB += s.PointsTeamB + s.AdderTeamB
+ }
+}
+
+type Step struct {
+ gorm.Model
+ GameID uint
+ Game Game `gorm:"foreignKey:GameID"`
+
+ PointsTeamA int
+ AdderTeamA int
+ PointsTeamB int
+ AdderTeamB int
}
func InitDB() *gorm.DB {
@@ -19,10 +43,10 @@ func InitDB() *gorm.DB {
if err != nil {
panic(err)
}
- db, err := gorm.Open(sqlite.Open(path.Join(home, "things.db")))
+ db, err := gorm.Open(sqlite.Open(path.Join(home, "tichu.db")))
if err != nil {
log.Panic(err)
}
- db.AutoMigrate(&Thing{})
+ db.AutoMigrate(Game{}, Step{})
return db
}
diff --git a/things/resource.go b/things/resource.go
deleted file mode 100644
index 140e909..0000000
--- a/things/resource.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package things
-
-import (
- "log"
- "wails-template/model"
-
- "gorm.io/gorm"
-)
-
-type Service struct {
- DB *gorm.DB
-}
-
-func (s *Service) NewThing(name string) {
- if err := s.DB.Save(&model.Thing{Name: name}).Error; err != nil {
- log.Fatal(err)
- }
-
- print(name)
-}
-
-func (s *Service) GetThings() (things []model.Thing) {
- if err := s.DB.Find(&things).Error; err != nil {
- log.Fatal(err)
- }
- return things
-}
-
-func (s *Service) DeleteThing(id int) {
- if err := s.DB.Delete(model.Thing{}, id).Error; err != nil {
- log.Fatal(err)
- }
-}
diff --git a/wails.json b/wails.json
index ce57698..aee446d 100644
--- a/wails.json
+++ b/wails.json
@@ -1,7 +1,7 @@
{
"$schema": "https://wails.io/schemas/config.v2.json",
- "name": "wails-template",
- "outputfilename": "wails-template",
+ "name": "tichu-counter",
+ "outputfilename": "tichu-counter",
"frontend:install": "pnpm install",
"frontend:build": "pnpm run build",
"frontend:dev:watcher": "pnpm run dev",