89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type World struct {
|
|
Id string
|
|
Title string
|
|
Description string
|
|
Compatibility Compatibility
|
|
System string
|
|
CoreVersion string
|
|
SystemVersion string
|
|
LastPlayed string
|
|
PlayTime int64
|
|
NextSession time.Time
|
|
}
|
|
|
|
type Worlds []World
|
|
|
|
func (worlds Worlds) GetById(id int) *World {
|
|
return &worlds[id]
|
|
}
|
|
|
|
func (state *FoundryState) GetWorld() World {
|
|
return World{
|
|
Id: state.World.Id,
|
|
Title: state.World.Title,
|
|
Description: state.World.Description,
|
|
Compatibility: Compatibility{
|
|
Minimum: state.World.Compatibility.Minimum,
|
|
Maximum: state.World.Compatibility.Maximum,
|
|
},
|
|
System: state.World.System,
|
|
CoreVersion: state.World.CoreVersion,
|
|
SystemVersion: state.World.SystemVersion,
|
|
LastPlayed: state.World.LastPlayed,
|
|
PlayTime: state.World.PlayTime,
|
|
NextSession: state.World.NextSession,
|
|
}
|
|
}
|
|
|
|
func (state *FoundryState) GetWorlds() Worlds {
|
|
worldsCopy := make([]World, 0, 8)
|
|
for i := range state.Worlds {
|
|
world := &(state.Worlds[i])
|
|
worldCopy := World{
|
|
Id: world.Id,
|
|
Title: world.Title,
|
|
Description: world.Description,
|
|
Compatibility: Compatibility{
|
|
Minimum: world.Compatibility.Minimum,
|
|
Maximum: world.Compatibility.Maximum,
|
|
},
|
|
System: world.System,
|
|
CoreVersion: world.CoreVersion,
|
|
SystemVersion: world.SystemVersion,
|
|
LastPlayed: world.LastPlayed,
|
|
PlayTime: world.PlayTime,
|
|
NextSession: world.NextSession,
|
|
}
|
|
worldsCopy = append(worldsCopy, worldCopy)
|
|
}
|
|
return worldsCopy
|
|
}
|
|
|
|
func (worlds Worlds) GetSessionTime(worldName string) (*time.Time, error) {
|
|
if worldName == "" && len(worlds) != 1 {
|
|
return nil, ErrorSetupNotFound
|
|
}
|
|
|
|
if worldName == "" {
|
|
return &worlds.GetById(0).NextSession, nil
|
|
} else {
|
|
for i := range worlds {
|
|
if worlds[i].Id == worldName {
|
|
return &worlds.GetById(0).NextSession, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, ErrorSetupNotFound
|
|
}
|
|
|
|
func (world World) GetSessionTime() *time.Time {
|
|
return &world.NextSession
|
|
}
|