{
  "code": "import { EventManager, EventType } from \"./EventManager\";\r\nimport { GameState } from \"./GameManager\";\r\nexport class Queue {\r\n    constructor() {\r\n        this.players = [];\r\n        Queue.instance = this;\r\n        this.InitQueue();\r\n    }\r\n    static get Instance() {\r\n        if (Queue.instance) {\r\n            return Queue.instance;\r\n        }\r\n        else {\r\n            return new Queue();\r\n        }\r\n    }\r\n    InitQueue() {\r\n        EventManager.GameStateEventOn(GameState.Win, this, this.OnGameEnd);\r\n        EventManager.GameStateEventOn(GameState.End, this, this.OnGameOver);\r\n        EventManager.GameStateEventOn(GameState.Playing, this, this.OnGamePlaying);\r\n        EventManager.EventOn(EventType.CompleteStage, this, this.OnPlayerStageChange);\r\n    }\r\n    signup(runner) {\r\n        this.players.push(runner);\r\n    }\r\n    OnGamePlaying() {\r\n        Laya.timer.once(1000, this, () => {\r\n            Laya.timer.frameLoop(1, this, this.SortPlayer);\r\n        });\r\n    }\r\n    OnGameEnd() {\r\n        Laya.timer.clear(this, this.SortPlayer);\r\n    }\r\n    OnGameOver() {\r\n        this.players = [];\r\n        Laya.timer.clear(this, this.SortPlayer);\r\n    }\r\n    OnPlayerStageChange() {\r\n        for (var i = 0; i < this.players.length; i++) {\r\n            if (this.players[i].Ai) {\r\n                if (this.players[i].die) {\r\n                    this.players[i].Cheat();\r\n                }\r\n            }\r\n        }\r\n    }\r\n    SortPlayer() {\r\n        this.players.sort(this.Sort);\r\n        EventManager.EventTrigger(EventType.PlayerRank, [this.players]);\r\n        if (this.Champion == null || this.Champion.Id != this.players[0].Id) {\r\n            this.Champion = this.players[0];\r\n            EventManager.EventTrigger(EventType.crownchange, this.players[0].Id);\r\n            EventManager.EventTrigger(EventType.ScoreChange, this.GetPlayerScore);\r\n        }\r\n    }\r\n    get GetPlayerScore() {\r\n        for (var i = 0; i < this.players.length; i++) {\r\n            var player = this.players[i];\r\n            if (!player.Ai) {\r\n                return i + 1;\r\n            }\r\n        }\r\n    }\r\n    Sort(a, b) {\r\n        if (a.m_sprite.transform.position.z > b.m_sprite.transform.position.z) {\r\n            return -1;\r\n        }\r\n        else {\r\n            return 1;\r\n        }\r\n    }\r\n}\r\n",
  "references": [
    "C:/Users/admin/Desktop/runner/src/Scripts/Game/Runner.ts",
    "C:/Users/admin/Desktop/runner/src/Scripts/Game/EventManager.ts",
    "C:/Users/admin/Desktop/runner/src/Scripts/Game/GameManager.ts"
  ]
}
