This repository was archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotfix.ts
38 lines (33 loc) · 1.48 KB
/
Hotfix.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { GameCreationOptions } from '../api/rules/GameCreationOptions'
import { Logger } from '../api/Logger'
import { Api } from '../api/Api'
/*
Hotfix for problems with state: reload application between games, forcing all memory to be gced
*/
export let Hotfix = {
__gameCreationFunction: null, //Private storage for the game creation function
isGameReload: function() {
return /game_/.test(window.location.hash)
},
reloadIntoGame: function(gco: GameCreationOptions) {
let logger = Logger.getLogger().focus('Hotfix', 'reloadIntoGame')
if (/game_/.test(window.location.hash)) {
window.location.hash = 'game_' + encodeURIComponent(JSON.stringify(gco)) //Store game creation options in hash
logger.log('Starting game by reloading (hash found)')
Api.stop()
window.location.reload()
} else {
window.location.hash = 'game_' + encodeURIComponent(JSON.stringify(gco)) //Store game creation options in hash
logger.log('Starting game directly')
Hotfix.__gameCreationFunction(gco)
}
},
init(gameCreationFunction) {
Hotfix.__gameCreationFunction = gameCreationFunction
if (/game_/.test(window.location.hash)) { //If there's a game to be started
Logger.getLogger().log('Hotfix', 'init', 'Hash found, starting game')
let gco = JSON.parse(decodeURIComponent(window.location.hash.substring('#game_'.length))) //Retrieve game creation options
gameCreationFunction(gco) //Start game
}
},
}