diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-22 18:48:59 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-22 18:48:59 +0100 |
commit | 006ce356220c1a089fc468bbfdc0dea819cd9288 (patch) | |
tree | b191563147dfda22a7b3fe4726fc65d81e78e874 /web/pw-server/src/lib | |
parent | 060b585da1d6beb7dc214d1eb70bcd73ac41ed86 (diff) | |
download | planetwars.dev-006ce356220c1a089fc468bbfdc0dea819cd9288.tar.xz planetwars.dev-006ce356220c1a089fc468bbfdc0dea819cd9288.zip |
persist bot code in localstorage
Diffstat (limited to 'web/pw-server/src/lib')
-rw-r--r-- | web/pw-server/src/lib/bot_code.ts | 15 | ||||
-rw-r--r-- | web/pw-server/src/lib/utils.ts | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/web/pw-server/src/lib/bot_code.ts b/web/pw-server/src/lib/bot_code.ts new file mode 100644 index 0000000..088db72 --- /dev/null +++ b/web/pw-server/src/lib/bot_code.ts @@ -0,0 +1,15 @@ +import defaultBotCode from "../assets/bot_template.txt?raw"; + +const BOT_CODE_KEY = "bot_code"; + +export function getBotCode() { + let botCode = localStorage.getItem(BOT_CODE_KEY); + if (!botCode) { + botCode = defaultBotCode; + } + return botCode; +} + +export function saveBotCode(botCode: string) { + localStorage.setItem(BOT_CODE_KEY, botCode); +} diff --git a/web/pw-server/src/lib/utils.ts b/web/pw-server/src/lib/utils.ts new file mode 100644 index 0000000..aab9734 --- /dev/null +++ b/web/pw-server/src/lib/utils.ts @@ -0,0 +1,9 @@ +export function debounce(func: Function, timeout: number = 300) { + let timer: ReturnType<typeof setTimeout>; + return (...args: any[]) => { + clearTimeout(timer); + timer = setTimeout(() => { + func.apply(this, args); + }, timeout); + }; +} |