node:crypto cannot be used clientside, so use phaser's UUID generator (I wanted to use phaser's uuid anyways but found node:crypto first)
This commit is contained in:
RedstonewolfX 2024-07-14 17:20:16 -04:00
parent dfc00c18f2
commit 607db5d091

View File

@ -13,7 +13,6 @@ import { TitlePhase } from "./phases";
import Trainer from "./field/trainer"; import Trainer from "./field/trainer";
import { Species } from "./enums/species"; import { Species } from "./enums/species";
import { GameMode, GameModes } from "./game-mode"; import { GameMode, GameModes } from "./game-mode";
import { randomUUID, UUID } from "node:crypto";
import PokemonSpecies from "./data/pokemon-species"; import PokemonSpecies from "./data/pokemon-species";
//#endregion //#endregion
@ -355,7 +354,9 @@ function updateLog(drpd: DRPD): DRPD {
} // 1.0.0 → 1.0.0a } // 1.0.0 → 1.0.0a
if (drpd.version == "1.0.0a") { if (drpd.version == "1.0.0a") {
drpd.version = "1.1.0" drpd.version = "1.1.0"
drpd.uuid = randomUUID() var RState = Phaser.Math.RND.state()
drpd.uuid = Phaser.Math.RND.uuid()
Phaser.Math.RND.state(RState)
drpd.label = "route" drpd.label = "route"
} // 1.0.0a → 1.1.0 } // 1.0.0a → 1.1.0
return drpd; return drpd;
@ -376,7 +377,7 @@ export interface DRPD {
/** The webpage path and internal name of this run. Entered by the user. Not to be confused with `title`, which is only a cosmetic identifier. */ /** The webpage path and internal name of this run. Entered by the user. Not to be confused with `title`, which is only a cosmetic identifier. */
label: string, label: string,
/** A unique ID for this run. Currently unused, but may be used in the future. */ /** A unique ID for this run. Currently unused, but may be used in the future. */
uuid: UUID, uuid: string,
/** The name(s) of the users that worked on this run. Entered by the user. */ /** The name(s) of the users that worked on this run. Entered by the user. */
authors: string[], authors: string[],
/** The date that this document was created on. Does NOT automatically detect the date of daily runs (It can't) */ /** The date that this document was created on. Does NOT automatically detect the date of daily runs (It can't) */
@ -409,16 +410,20 @@ export function importDocument(drpd: string): DRPD {
* @returns The fresh DRPD document. * @returns The fresh DRPD document.
*/ */
export function newDocument(name: string = "Untitled Run", authorName: string | string[] = "Write your name here"): DRPD { export function newDocument(name: string = "Untitled Run", authorName: string | string[] = "Write your name here"): DRPD {
return { var ret: DRPD = {
version: DRPD_Version, version: DRPD_Version,
title: name, title: name,
label: "", label: "",
uuid: randomUUID(), uuid: undefined,
authors: (Array.isArray(authorName) ? authorName : [authorName]), authors: (Array.isArray(authorName) ? authorName : [authorName]),
date: new Date().getUTCFullYear() + "-" + (new Date().getUTCMonth() + 1 < 10 ? "0" : "") + (new Date().getUTCMonth() + 1) + "-" + (new Date().getUTCDate() < 10 ? "0" : "") + new Date().getUTCDate(), date: new Date().getUTCFullYear() + "-" + (new Date().getUTCMonth() + 1 < 10 ? "0" : "") + (new Date().getUTCMonth() + 1) + "-" + (new Date().getUTCDate() < 10 ? "0" : "") + new Date().getUTCDate(),
waves: new Array(50), waves: new Array(50),
starters: new Array(3), starters: new Array(3),
} }
var RState = Phaser.Math.RND.state()
ret.uuid = Phaser.Math.RND.uuid()
Phaser.Math.RND.state(RState)
return ret;
} }
/** /**
* Prints a DRPD as a string, for saving it to your device. * Prints a DRPD as a string, for saving it to your device.