From 625000c3082300f58197d6cf6d6089f27f65244a Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Mon, 27 Sep 2021 18:22:35 +0200 Subject: [PATCH] Minimal HomeAction and Tabs --- src/components/Game.svelte | 16 ++++ .../ResourceTable/ResourceGroup.svelte | 5 +- .../ResourceTable/ResourceTable.svelte | 94 ++++--------------- src/components/TabSelector.svelte | 71 ++++++++++++++ src/components/Tabs/Home.svelte | 41 ++++++++ src/components/Tabs/Lab.svelte | 1 + src/components/Wrapper.svelte | 16 +++- src/global.d.ts | 8 ++ src/shark/SharkGame.ts | 6 +- src/shark/Tabs.ts | 11 +++ src/shark/data/HomeActions.ts | 73 ++++++++++++++ src/shark/data/Resources.ts | 73 ++++++++++++++ src/styles/global.scss | 7 +- tsconfig.json | 6 +- 14 files changed, 347 insertions(+), 81 deletions(-) create mode 100644 src/components/Game.svelte create mode 100644 src/components/TabSelector.svelte create mode 100644 src/components/Tabs/Home.svelte create mode 100644 src/components/Tabs/Lab.svelte create mode 100644 src/shark/Tabs.ts create mode 100644 src/shark/data/HomeActions.ts create mode 100644 src/shark/data/Resources.ts diff --git a/src/components/Game.svelte b/src/components/Game.svelte new file mode 100644 index 0000000..32f5360 --- /dev/null +++ b/src/components/Game.svelte @@ -0,0 +1,16 @@ + + +
+ +
+ + diff --git a/src/components/ResourceTable/ResourceGroup.svelte b/src/components/ResourceTable/ResourceGroup.svelte index b9b469d..c7d9853 100644 --- a/src/components/ResourceTable/ResourceGroup.svelte +++ b/src/components/ResourceTable/ResourceGroup.svelte @@ -1,10 +1,11 @@ diff --git a/src/components/ResourceTable/ResourceTable.svelte b/src/components/ResourceTable/ResourceTable.svelte index e4bc3f3..0366929 100644 --- a/src/components/ResourceTable/ResourceTable.svelte +++ b/src/components/ResourceTable/ResourceTable.svelte @@ -1,85 +1,29 @@ - - - + + +
+ +
+ + diff --git a/src/components/Tabs/Home.svelte b/src/components/Tabs/Home.svelte new file mode 100644 index 0000000..c671a06 --- /dev/null +++ b/src/components/Tabs/Home.svelte @@ -0,0 +1,41 @@ + + +
+ {#each Object.entries(HomeActions.getActionTable()) as [homeActionId, homeAction]} + + {/each} +
+ + diff --git a/src/components/Tabs/Lab.svelte b/src/components/Tabs/Lab.svelte new file mode 100644 index 0000000..af62d02 --- /dev/null +++ b/src/components/Tabs/Lab.svelte @@ -0,0 +1 @@ +Haha, Laboratory go BRRRRRRRRRRRRRRR! diff --git a/src/components/Wrapper.svelte b/src/components/Wrapper.svelte index 06df4b5..9f20fbf 100644 --- a/src/components/Wrapper.svelte +++ b/src/components/Wrapper.svelte @@ -1,14 +1,23 @@
- +
+
+ + +
diff --git a/src/global.d.ts b/src/global.d.ts index 1a25456..74ad4c4 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1 +1,9 @@ /// + +import type { SharkGame } from "./shark/SharkGame"; + +declare global { + interface Window { + SharkGame: SharkGame; + } +} diff --git a/src/shark/SharkGame.ts b/src/shark/SharkGame.ts index f728b71..e611022 100644 --- a/src/shark/SharkGame.ts +++ b/src/shark/SharkGame.ts @@ -1,6 +1,8 @@ +import { Resources } from "./data/Resources"; import { Log } from "./Log"; import { Settings } from "./Settings"; import { StaticClass } from "./StaticClass"; +import { Tabs } from "./Tabs"; export class SharkGame extends StaticClass { static readonly #GAME_NAMES = [ @@ -55,6 +57,8 @@ export class SharkGame extends StaticClass { static title: string; static readonly Settings = Settings; static readonly Log = Log; + static readonly Resources = Resources; + static readonly Tabs = Tabs; static init(): void { for (const setting of Object.values(Settings)) { @@ -68,4 +72,4 @@ export class SharkGame extends StaticClass { } } -globalThis.SharkGame = SharkGame; +window.SharkGame = SharkGame; diff --git a/src/shark/Tabs.ts b/src/shark/Tabs.ts new file mode 100644 index 0000000..c98cae0 --- /dev/null +++ b/src/shark/Tabs.ts @@ -0,0 +1,11 @@ +import Home from "../components/Tabs/Home.svelte"; +import Lab from "../components/Tabs/Lab.svelte"; +import { StaticClass } from "./StaticClass"; + +export class Tabs extends StaticClass { + static readonly Tabs = { + Home, + Lab, + } as const; + static currentTab: keyof typeof Tabs.Tabs = "Home"; +} diff --git a/src/shark/data/HomeActions.ts b/src/shark/data/HomeActions.ts new file mode 100644 index 0000000..c5fe2d8 --- /dev/null +++ b/src/shark/data/HomeActions.ts @@ -0,0 +1,73 @@ +import { StaticClass } from "../StaticClass"; + +export type HomeAction = { + name: string; + effect: { + resource: Record; + }; + outcomes: string[]; + multiOutcomes?: string[]; + helpText: string; +}; + +export class HomeActions extends StaticClass { + static getActionTable(): { [actionName: string]: HomeAction } { + return HomeActions.actionTable; + } + + static actionTable = { + catchFish: { + name: "Catch fish", + effect: { + resource: { + fish: 1, + }, + }, + cost: {}, + prereq: {}, + outcomes: [ + "Dropped the bass.", + "Ate a kipper. Wait. Hang on.", + "You eat a fish hooray!", + "Fish.", + "Ate a shark. Wait. No, it wasn't a shark.", + "Ate an anchovy.", + "Ate a catfish.", + "Ate a flounder.", + "Ate a haddock.", + "Ate a herring.", + "Ate a mackerel.", + "Ate a mullet.", + "Ate a perch.", + "Ate a pollock.", + "Ate a salmon.", + "Ate a sardine.", + "Ate a sole.", + "Ate a tilapia.", + "Ate a trout.", + "Ate a whitefish.", + "Ate a bass.", + "Ate a carp.", + "Ate a cod.", + "Ate a halibut.", + "Ate a mahi mahi.", + "Ate a monkfish.", + "Ate a perch.", + "Ate a snapper.", + "Ate a bluefish.", + "Ate a grouper.", + "Ate a sea bass.", + "Ate a yellowfin tuna.", + "Ate a marlin.", + "Ate an orange roughy.", + "Ate a shark.", + "Ate a swordfish.", + "Ate a tilefish.", + "Ate a tuna.", + "Ate a swedish fish.", + "Ate a goldfish.", + ], + helpText: "Use your natural shark prowess to find and catch a fish.", + }, + }; +} diff --git a/src/shark/data/Resources.ts b/src/shark/data/Resources.ts new file mode 100644 index 0000000..d1c5ba6 --- /dev/null +++ b/src/shark/data/Resources.ts @@ -0,0 +1,73 @@ +import { writable } from "svelte/store"; + +import { StaticClass } from "../StaticClass"; + +export class Resource { + category: string; + amount: number; + change: number; + + constructor(category: string) { + this.category = category; + this.amount = 0; + this.change = 0; + } +} + +export class Resources extends StaticClass { + static readonly Resources = writable>({ + shark: new Resource("Frenzy"), + ray: new Resource("Frenzy"), + fish: new Resource("Animals"), + }); + + static createResource(name: string, category: string): void { + Resources.Resources.update((res) => { + res[name] = new Resource(category); + return res; + }); + } + + static setResource(resourceName: string, amount: number): void { + Resources.Resources.update((res) => { + res[resourceName].amount = amount; + return res; + }); + } + + static getResource(resourceName: string): Resource | null { + let result: null | Resource = null; + Resources.Resources.update((res) => { + if (Object.hasOwnProperty.call(res, resourceName)) + result = res[resourceName]; + return res; + }); + return result; + } + + static getResources(resourceNames: string[]): Record | null; + static getResources( + ...resourceNames: string[] + ): Record | null; + static getResources( + ...resourceNames: string[] | string[][] + ): Record | null { + if (Array.isArray(resourceNames[0])) { + resourceNames = resourceNames[0]; + } + + let result: null | [string, Resource][] = null; + Resources.Resources.update((res) => { + for (const resourceName of resourceNames as string[]) { + if (Object.hasOwnProperty.call(res, resourceName)) { + if (result === null) { + result = []; + } + result.push([resourceName, res[resourceName]]); + } + } + return res; + }); + return result === null ? null : Object.fromEntries(result); + } +} diff --git a/src/styles/global.scss b/src/styles/global.scss index fbd9daf..7749959 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -23,13 +23,18 @@ a { button { background-color: var(--color-light); border: 1px solid var(--color-lighter); - border-radius: 10px; + border-radius: 5px; text-shadow: 0 0 2px black; color: white; &:hover { box-shadow: 0 0 2px 2px var(--color-lighter); } + &:active { + background-color: var(--color-dark); + color: var(--color-light); + box-shadow: 0 3px 7px 7px var(--color-darker) inset; + } &:not(:disabled) { cursor: pointer; diff --git a/tsconfig.json b/tsconfig.json index 41051d9..f9eac3a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,5 +4,9 @@ "target": "es2021", "include": ["src/**/*"], - "exclude": ["node_modules/*", "__sapper__/*", "public/*"] + "exclude": ["node_modules/*", "__sapper__/*", "public/*"], + + "compilerOptions": { + "strict": true + } }