diff --git a/content/core/actions/CoreActions.ts b/content/core/actions/CoreActions.ts index 3fd98eb..020d6c0 100644 --- a/content/core/actions/CoreActions.ts +++ b/content/core/actions/CoreActions.ts @@ -19,14 +19,14 @@ import { GATHER_FLINT, MAKE_ARROWHEAD } from '../tasks/CoreTasks.js'; // }) // }); -registerAction('Gather Flint', (qty) => { +registerAction('Gather Flint', () => { const taskState = new TaskState(GATHER_FLINT); Game.current.board.addTask(taskState); }); registerAction('Create Arrowhead', (qty) => { const rock = new ItemState(FLINT_NORMAL, 1, null); - const task = new TaskState(MAKE_ARROWHEAD).setData({ + const task = new TaskState(MAKE_ARROWHEAD, { baseMaterial: rock }); diff --git a/content/core/tasks/CoreTasks.ts b/content/core/tasks/CoreTasks.ts index 0259102..04ecb0f 100644 --- a/content/core/tasks/CoreTasks.ts +++ b/content/core/tasks/CoreTasks.ts @@ -2,6 +2,8 @@ import { Task } from "@tasks"; import { Game } from '@game'; import { FLINT_NORMAL, SLATE_NORMAL } from '../items/CoreItems.js'; import { ItemState } from "@items"; +import { Popup } from "../../../src/ui/Popup.js"; +import { inspect } from 'util'; export const GATHER_FLINT = new Task('core:gather-flint') .setName('Gather Flint') @@ -12,28 +14,16 @@ export const GATHER_FLINT = new Task('core:gather-flint') .setCompletionEvent(() => { const qty = Math.floor(Math.random() * 5) + 1; Game.current.inv.add(new ItemState(FLINT_NORMAL, 1, null)); - }) - -// export const GATHER_SLATE = new Task('core:gather-slate') -// .setName('Gather Slate') -// .setStatus('SCAVENGING') -// .setWork(1000) -// .setTasklistVisibility(true) -// .setCategory("work") -// .setCompletionEvent(() => { -// const qty = Math.floor(Math.random() * 5) + 1; -// Game.current.inv.add(SLATE_NORMAL, qty); -// }); + }); export const MAKE_ARROWHEAD = new Task<{ baseMaterial: ItemState }>('core:gather-slate') .setName('Gather Slate') .setStatus('SCAVENGING') - .setWork(1000) + .setWork(1) .setTasklistVisibility(true) .setCategory("work") .setCompletionEvent((data) => { - const qty = Math.floor(Math.random() * 5) + 1; - Game.current.inv.add(SLATE_NORMAL, qty); + Popup.show(inspect(data)); }); \ No newline at end of file diff --git a/src/TaskList.ts b/src/TaskList.ts index 40c3fe7..a080313 100644 --- a/src/TaskList.ts +++ b/src/TaskList.ts @@ -2,6 +2,8 @@ import { Serializable } from 'frigid'; import { Task, TaskState } from './registries/Tasks.js'; import { render, Renderable, panels } from './ui/UI.js'; +const taskTypes = {}; + export class TaskList extends Serializable implements Renderable { tasks: TaskState[] = []; @@ -32,7 +34,6 @@ export class TaskList extends Serializable implements Renderable { } } -const taskTypes = {}; -export function registerTask(name, clazz) { - taskTypes[name] = clazz; -} \ No newline at end of file +// export function registerTask(name, clazz) { +// taskTypes[name] = clazz; +// } \ No newline at end of file diff --git a/src/registries/Items.ts b/src/registries/Items.ts index 6acd310..b7d9919 100644 --- a/src/registries/Items.ts +++ b/src/registries/Items.ts @@ -6,14 +6,14 @@ export type ItemID = string; const items = new Map(); +export type PropertyValue = number | boolean; + // ITEMS SHALL BE SINGULAR export class Item extends Serializable { name = ''; id: ItemID = ''; - props: { - [propName: string]: any - }; + props: Map = new Map(); setName(name) { this.name = name; @@ -40,7 +40,8 @@ export class Item extends Serializable { } getProperty(prop: ItemProperty) { - return this.props[prop.name] ?? null; + if(this.props.has(prop.name)) return this.props.get(prop.name); + else return null; } } diff --git a/src/registries/Tasks.ts b/src/registries/Tasks.ts index 0d8f96f..22ae815 100644 --- a/src/registries/Tasks.ts +++ b/src/registries/Tasks.ts @@ -6,7 +6,7 @@ import { Game } from '../Game.js'; import { panels } from '../ui/UI.js'; import { progressbar, ProgressbarStyle } from '../Progressbar.js'; -const tasks: Map> = new Map(); +export const tasks: Map> = new Map(); export type TaskCategory = "self" | "work" | "craft" | "idle"; export class Task { @@ -67,18 +67,13 @@ export class TaskState extends Serializable { this.testCompletion(); } - constructor(task: Task) { + constructor(task: Task, data: T = {} as T) { super(); this.taskId = task.id; this.progress = 0; this.worker = null; // preset the data to nothing JIC - this.data = {} as T; - } - - setData(data: T) { this.data = data; - return this; } stopJob() { @@ -92,7 +87,7 @@ export class TaskState extends Serializable { } testCompletion() { - if (this.completed) { + if (this.taskId && this.completed) { this.task.completionEvent(this.data); Game.current.board.removeTask(this); } diff --git a/src/ui/Menu.ts b/src/ui/Menu.ts index 46667a4..56bc581 100644 --- a/src/ui/Menu.ts +++ b/src/ui/Menu.ts @@ -11,6 +11,7 @@ import InventoryView from './view/InventoryView.js'; import MultiplayerView from './view/MultiplayerView.js'; import { View } from './View.js'; import { ActionsView } from './view/ActionsView.js'; +import { tasks } from '@tasks'; const clamp = (min, max, value) => Math.min(Math.max(value, min), max); @@ -55,6 +56,10 @@ export class Menu implements Renderable { // debugging hotkeys } else if (key.full === '1') { Popup.show(inspect(stats)); + } else if (key.full === '2') { + Popup.show(inspect(tasks)); + } else if (key.full === '3') { + Popup.show(inspect(stats)); } else if (key.full === 'z') { Game.current.pawns.push(new Pawn()); } else if (key.full === 'x') {