Flint works, arrowheads... almost. BASEMAT DATA!

master
Bronwen 2021-06-25 23:08:45 -04:00
parent d11741dc02
commit 4da31d058e
6 changed files with 25 additions and 33 deletions

View File

@ -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
});

View File

@ -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));
});

View File

@ -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<any>[] = [];
@ -32,7 +34,6 @@ export class TaskList extends Serializable implements Renderable {
}
}
const taskTypes = {};
export function registerTask(name, clazz) {
taskTypes[name] = clazz;
}
// export function registerTask(name, clazz) {
// taskTypes[name] = clazz;
// }

View File

@ -6,14 +6,14 @@ export type ItemID = string;
const items = new Map<ItemID, Item>();
export type PropertyValue = number | boolean;
// ITEMS SHALL BE SINGULAR
export class Item extends Serializable {
name = '';
id: ItemID = '';
props: {
[propName: string]: any
};
props: Map<string, PropertyValue> = 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;
}
}

View File

@ -6,7 +6,7 @@ import { Game } from '../Game.js';
import { panels } from '../ui/UI.js';
import { progressbar, ProgressbarStyle } from '../Progressbar.js';
const tasks: Map<string, Task<any>> = new Map();
export const tasks: Map<string, Task<any>> = new Map();
export type TaskCategory = "self" | "work" | "craft" | "idle";
export class Task<Data> {
@ -67,18 +67,13 @@ export class TaskState<T> extends Serializable {
this.testCompletion();
}
constructor(task: Task<T>) {
constructor(task: Task<T>, 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<T> extends Serializable {
}
testCompletion() {
if (this.completed) {
if (this.taskId && this.completed) {
this.task.completionEvent(this.data);
Game.current.board.removeTask(this);
}

View File

@ -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') {