ds4/src/actor/proxy.ts
2022-02-17 01:03:29 +01:00

23 lines
782 B
TypeScript

// 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);