refactor: use subclasses for different actor types
This commit is contained in:
parent
21f849b464
commit
be616e3be8
23 changed files with 321 additions and 240 deletions
23
src/actor/proxy.ts
Normal file
23
src/actor/proxy.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
// SPDX-FileCopyrightText: 2022 Johannes Loher
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { getGame } from "../helpers";
|
||||
import { DS4Actor } from "./actor";
|
||||
import { DS4Character } from "./character/character";
|
||||
import { DS4Creature } from "./creature/creature";
|
||||
|
||||
const handler = {
|
||||
construct(_: typeof DS4Actor, args: ConstructorParameters<typeof DS4Actor>) {
|
||||
switch (args[0]?.type) {
|
||||
case "character":
|
||||
return new DS4Character(...args);
|
||||
case "creature":
|
||||
return new DS4Creature(...args);
|
||||
default:
|
||||
throw new Error(getGame().i18n.format("DS4.ErrorInvalidActorType", { type: args[0]?.type }));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const DS4ActorProxy: typeof DS4Actor = new Proxy(DS4Actor, handler);
|
Loading…
Add table
Add a link
Reference in a new issue