Engine entity work
This commit is contained in:
@@ -21,13 +21,18 @@ import {
|
||||
import { Mob, type MobCategory } from "./mob.ts";
|
||||
|
||||
// the entity's class. the attributes are read while LivingEntity is being built, before any field of a subclass is
|
||||
// set, so each kind gets its own class that has its json already
|
||||
export function mod_entity_factory(json: EntityJson): EntityFactory {
|
||||
// set, so each kind gets its own class that has its json already. behaviors are mods' (see ctx.entities), looked up
|
||||
// when a mob first thinks, after every script has registered its own
|
||||
export function mod_entity_factory(
|
||||
json: EntityJson,
|
||||
behaviors: ReadonlyMap<string, (mob: Mob) => void>,
|
||||
): EntityFactory {
|
||||
if (json.behavior === "scripted") {
|
||||
return (level) => new ScriptedEntity(level, json);
|
||||
}
|
||||
|
||||
const monster = json.behavior === "monster";
|
||||
const behavior = json.behavior?.includes(":") ? json.behavior : undefined;
|
||||
const category = entity_category(json);
|
||||
|
||||
class ModEntity extends Mob {
|
||||
@@ -52,6 +57,10 @@ export function mod_entity_factory(json: EntityJson): EntityFactory {
|
||||
}
|
||||
|
||||
override register_goals() {
|
||||
if (behavior) {
|
||||
behaviors.get(behavior)!(this);
|
||||
return;
|
||||
}
|
||||
if (monster) {
|
||||
// like undergarden's rotspawn and minecraft's zombies
|
||||
this.goals.add_goal(0, new FloatGoal(this));
|
||||
|
||||
Reference in New Issue
Block a user