game state can be read out by the client APIs
# Conflicts: # front/src/Api/IframeListener.ts # front/src/Phaser/Game/GameScene.ts # front/src/iframe_api.ts
This commit is contained in:
parent
5dc2f0ac47
commit
3836d5037c
5 changed files with 74 additions and 0 deletions
18
front/src/utility.ts
Normal file
18
front/src/utility.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
export function deepFreezeClone<T> (obj:T):Readonly<T> {
|
||||
return deepFreeze(JSON.parse(JSON.stringify(obj)));
|
||||
}
|
||||
|
||||
function deepFreeze<T> (obj:T):T{
|
||||
Object.freeze(obj);
|
||||
if (obj === undefined) {
|
||||
return obj;
|
||||
}
|
||||
const propertyNames = Object.getOwnPropertyNames(obj) as Array<keyof T>;
|
||||
propertyNames.forEach(function (prop) {
|
||||
if (obj[prop] !== null&& (typeof obj[prop] === "object" || typeof obj[prop] === "function") && !Object.isFrozen(obj[prop])) {
|
||||
deepFreezeClone(obj[prop]);
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue