From 2908670e0dd6eafb991221ed1628c3e1152a5cea Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Tue, 9 May 2023 14:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0MarshalJSON=E5=92=8CUnmarshal?= =?UTF-8?q?JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/builtin/ranking_list.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game/builtin/ranking_list.go b/game/builtin/ranking_list.go index 8ae7fac..63738d4 100644 --- a/game/builtin/ranking_list.go +++ b/game/builtin/ranking_list.go @@ -233,6 +233,7 @@ func (slf *RankingList[CompetitorID, Score]) UnmarshalJSON(bytes []byte) error { var t struct { Competitors *synchronization.Map[CompetitorID, Score] `json:"competitors,omitempty"` Scores []*scoreItem[CompetitorID, Score] `json:"scores,omitempty"` + Asc bool `json:"asc,omitempty"` } t.Competitors = synchronization.NewMap[CompetitorID, Score]() if err := json.Unmarshal(bytes, &t); err != nil { @@ -240,6 +241,7 @@ func (slf *RankingList[CompetitorID, Score]) UnmarshalJSON(bytes []byte) error { } slf.competitors = t.Competitors slf.scores = t.Scores + slf.asc = t.Asc return nil } @@ -247,9 +249,11 @@ func (slf *RankingList[CompetitorID, Score]) MarshalJSON() ([]byte, error) { var t struct { Competitors *synchronization.Map[CompetitorID, Score] `json:"competitors,omitempty"` Scores []*scoreItem[CompetitorID, Score] `json:"scores,omitempty"` + Asc bool `json:"asc,omitempty"` } t.Competitors = slf.competitors t.Scores = slf.scores + t.Asc = slf.asc return json.Marshal(&t) }