Documentation ¶
Index ¶
- func FormatDuration(d time.Duration) string
- func Migrate() error
- type Level
- type LevelPack
- type SaveGame
- func (sg *SaveGame) CountCompleted(levelpack *levelpack.LevelPack) int
- func (sg *SaveGame) GetLevelScore(levelpack, filename, uuid string) *Level
- func (sg *SaveGame) MarkCompleted(levelpack, filename, uuid string)
- func (sg *SaveGame) NewHighScore(levelpack, filename, uuid string, isPerfect bool, elapsed time.Duration, ...) bool
- func (sg *SaveGame) Save() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration pretty prints a time.Duration in MM:SS format.
func Migrate ¶
func Migrate() error
Migrate the savegame.json file to re-save it as its newest file format.
v0: we stored LevelPack filenames + level filenames to store high scores. This was brittle in case a level gets moved into another levelpack later, or either it or the levelpack is renamed.
v1: levels get UUID numbers and we store them by that. You can re-roll a UUID in the level editor if you want to break high scores for your new level version.
Types ¶
type Level ¶
type Level struct { Completed bool `json:"completed"` BestTime *time.Duration `json:"bestTime"` PerfectTime *time.Duration `json:"perfectTime"` }
Level holds high score information for a level.
type SaveGame ¶
type SaveGame struct { // DEPRECATED: savegame state spelled out by level packs and // filenames. LevelPacks map[string]*LevelPack `json:"levelPacks,omitempty"` // New data format: store high scores by level UUID. Adds a // nice layer of obfuscation + is more robust in case levels // move around between levelpacks, get renamed, etc. that // the user should be able to keep their high score. Levels map[string]*Level }
SaveGame holds the user's progress thru level packs.
func GetOrCreate ¶
GetOrCreate the save game JSON. If the save file isn't found OR has an invalid checksum, it is created. Always returns a valid SaveGame struct and the error may communicate if there was a problem reading an existing file.
func (*SaveGame) CountCompleted ¶
CountCompleted returns the number of completed levels in a levelpack.
func (*SaveGame) GetLevelScore ¶
GetLevelScore finds or creates a default Level score.
func (*SaveGame) MarkCompleted ¶
MarkCompleted is a helper function to mark a levelpack level completed. Parameters are the filename of the levelpack and the level therein. Extra path info except the base filename is stripped from both.
func (*SaveGame) NewHighScore ¶
func (sg *SaveGame) NewHighScore(levelpack, filename, uuid string, isPerfect bool, elapsed time.Duration, rules level.GameRule) bool
NewHighScore may set a new highscore for a level.
The level will be marked Completed and if the given score is better than the stored one it will update.
Returns true if a new high score was logged.