41 lines
923 B
Go
41 lines
923 B
Go
package scoreboard
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
|
)
|
|
|
|
type StageRecord struct {
|
|
StageName string `json:"stagename"`
|
|
StageResults []stage.StageResult `json:"stageresults"`
|
|
}
|
|
|
|
type ScoreboardData struct {
|
|
StageRecords []StageRecord `json:"stagerecords"`
|
|
}
|
|
|
|
type Scoreboard struct {
|
|
scoreboard ScoreboardData
|
|
}
|
|
|
|
func (b *Scoreboard) Init() {
|
|
b.scoreboard.StageRecords = make([]StageRecord, 0)
|
|
}
|
|
|
|
func (b *Scoreboard) AddScore(stagename string, results []stage.StageResult) {
|
|
b.scoreboard.StageRecords = append(b.scoreboard.StageRecords,
|
|
StageRecord{StageName: stagename, StageResults: results})
|
|
}
|
|
|
|
func (b *Scoreboard) SaveFile(filePath string) {
|
|
json_file, _ := os.Create(filePath)
|
|
defer json_file.Close()
|
|
|
|
encoder := json.NewEncoder(json_file)
|
|
encoder.SetEscapeHTML(false)
|
|
encoder.SetIndent("", " ")
|
|
_ = encoder.Encode(b.scoreboard)
|
|
}
|