ictgj-voting/model_gamejam.go

70 lines
1.1 KiB
Go
Raw Normal View History

2017-10-02 13:44:55 +00:00
package main
2017-10-11 23:03:27 +00:00
import "time"
2017-10-02 13:44:55 +00:00
2017-10-11 23:03:27 +00:00
/**
* Gamejam
* Gamejam is the struct for any gamejam (current or archived)
*/
2017-10-02 13:44:55 +00:00
type Gamejam struct {
UUID string
Name string
Date time.Time
Teams []Team
Votes []Vote
2017-10-12 13:51:53 +00:00
m *model // The model that holds this gamejam's data
mPath []string // The path in the db to this gamejam
2017-10-11 23:03:27 +00:00
updates []string
2017-10-02 13:44:55 +00:00
}
2017-10-11 23:03:27 +00:00
func NewGamejam(m *model) *Gamejam {
gj := new(Gamejam)
gj.m = m
2017-10-12 13:51:53 +00:00
gj.mPath = []string{"jam"}
2017-10-11 23:03:27 +00:00
return gj
2017-10-02 13:44:55 +00:00
}
2017-10-11 23:03:27 +00:00
func (m *model) LoadCurrentJam() *Gamejam {
if err := m.openDB(); err != nil {
return err
2017-10-02 13:44:55 +00:00
}
2017-10-11 23:03:27 +00:00
defer m.closeDB()
2017-10-02 13:44:55 +00:00
2017-10-11 23:03:27 +00:00
var err error
gj := NewGamejam(m)
2017-10-12 13:51:53 +00:00
gj.Name, _ = m.bolt.GetValue(gj.mPath, "name")
2017-10-11 23:03:27 +00:00
// Load all teams
gj.Teams = gj.LoadAllTeams()
// Load all votes
gj.Votes = gj.LoadAllVotes()
return gj
2017-10-02 13:44:55 +00:00
}
2017-10-11 23:03:27 +00:00
func (gj *Gamejam) getTeamByUUID(uuid string) *Team {
for i := range gj.Teams {
if gj.Teams[i].UUID == uuid {
return &gj.Teams[i]
}
2017-10-02 13:44:55 +00:00
}
2017-10-11 23:03:27 +00:00
return nil
}
2017-10-02 13:44:55 +00:00
2017-10-11 23:03:27 +00:00
func (gj *Gamejam) needsSave() bool {
return len(updates) > 0
2017-10-02 13:44:55 +00:00
}
2017-10-11 23:03:27 +00:00
func (gj *Gamejam) saveToDB() error {
2017-10-12 13:51:53 +00:00
if err := gj.m.openDB(); err != nil {
2017-10-02 13:44:55 +00:00
return err
}
2017-10-12 13:51:53 +00:00
defer gj.m.closeDB()
2017-10-02 13:44:55 +00:00
2017-10-11 23:03:27 +00:00
for i := range updates {
// TODO: Save
2017-10-02 13:44:55 +00:00
}
}