Begin ItemProps and TaskStates
parent
b6a0cd4811
commit
204e5bdad6
|
|
@ -1,4 +1,4 @@
|
||||||
import { Item } from '@items';
|
import { Item, ItemFilter, ItemProperty, ItemState } from '@items';
|
||||||
|
|
||||||
export const LOG = new Item().setName("Log").setId('core:resources/log');
|
export const LOG = new Item().setName("Log").setId('core:resources/log');
|
||||||
export const STICK = new Item().setName("Stick").setId('core:resources/stick');
|
export const STICK = new Item().setName("Stick").setId('core:resources/stick');
|
||||||
|
|
@ -28,4 +28,12 @@ export const OBSIDIAN_ARROWHEAD = new Item().setName("Obsidian Arrowhead").setId
|
||||||
export const OBSIDIAN_SPEAR = new Item().setName("Obsidian Spear").setId('core:obsidian-spear');
|
export const OBSIDIAN_SPEAR = new Item().setName("Obsidian Spear").setId('core:obsidian-spear');
|
||||||
|
|
||||||
// tools: plant fibres = rope, flint hatchet
|
// tools: plant fibres = rope, flint hatchet
|
||||||
// shale - igneous. metamorphasis => slate
|
// shale - igneous. metamorphasis => slate
|
||||||
|
|
||||||
|
export const SHARPNESS = new ItemProperty('core:sharpness');
|
||||||
|
|
||||||
|
export function minSharpness(min: number) {
|
||||||
|
return function(itemState: ItemState): boolean {
|
||||||
|
return itemState.item.getProperty(SHARPNESS) >= min;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,9 @@ export class Item extends Serializable {
|
||||||
|
|
||||||
name = '';
|
name = '';
|
||||||
id: ItemID = '';
|
id: ItemID = '';
|
||||||
|
props: {
|
||||||
|
[propName: string]: any
|
||||||
|
};
|
||||||
|
|
||||||
setName(name) {
|
setName(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
@ -30,6 +33,14 @@ export class Item extends Serializable {
|
||||||
items.set(this.id, this);
|
items.set(this.id, this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setProperty(prop: ItemProperty, value: any) {
|
||||||
|
this.props[prop.name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
getProperty(prop: ItemProperty) {
|
||||||
|
return this.props[prop.name] ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ItemState extends Serializable implements Renderable {
|
export class ItemState extends Serializable implements Renderable {
|
||||||
|
|
@ -55,3 +66,12 @@ export class ItemState extends Serializable implements Renderable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ItemProperty {
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
constructor(name: string) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ItemFilter = (itemState: ItemState) => boolean;
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,11 @@ import { progressbar, ProgressbarStyle } from '../Progressbar.js';
|
||||||
|
|
||||||
export const taskClasses: Map<string, typeof Task> = new Map();
|
export const taskClasses: Map<string, typeof Task> = new Map();
|
||||||
|
|
||||||
export abstract class Task extends Serializable {
|
export class Task {
|
||||||
progress = 0;
|
progress = 0;
|
||||||
worker: Pawn;
|
worker: Pawn;
|
||||||
data: any;
|
data: any;
|
||||||
|
id: string;
|
||||||
|
|
||||||
ctor() {
|
ctor() {
|
||||||
this.worker ??= null;
|
this.worker ??= null;
|
||||||
|
|
@ -66,9 +67,17 @@ export abstract class Task extends Serializable {
|
||||||
get status() {
|
get status() {
|
||||||
return chalk.bgRedBright.black('DOING A TASK');
|
return chalk.bgRedBright.black('DOING A TASK');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setId(id: string) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerTask(id: string, taskClass: typeof Task) {
|
export class TaskState extends Serializable {
|
||||||
console.log('Registered task', id);
|
|
||||||
taskClasses.set(id, taskClass)
|
constructor(task: Task) {
|
||||||
|
super();
|
||||||
|
this._taskId = task.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue