ds4/src/actor/actor-data-source.ts

126 lines
3.5 KiB
TypeScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
// SPDX-FileCopyrightText: 2021 Oliver Rümpelein
// SPDX-FileCopyrightText: 2021 Gesina Schwalbe
// SPDX-FileCopyrightText: 2021 Siegfried Krug
//
// SPDX-License-Identifier: MIT
import { ModifiableData, ModifiableDataBase, ResourceData, UsableResource } from "../common/common-data";
2021-02-05 03:42:42 +01:00
import { DS4 } from "../config";
2021-06-30 02:17:54 +02:00
declare global {
interface SourceConfig {
Actor: DS4ActorDataSource;
}
}
2021-01-26 03:55:18 +01:00
2021-06-30 02:17:54 +02:00
export type DS4ActorDataSource = DS4CharacterDataSource | DS4CreatureDataSource;
2021-06-30 02:17:54 +02:00
interface DS4CharacterDataSource {
type: "character";
data: DS4CharacterDataSourceData;
2020-12-28 15:51:00 +01:00
}
2021-06-30 02:17:54 +02:00
interface DS4CreatureDataSource {
type: "creature";
data: DS4CreatureDataSourceData;
}
2021-02-05 03:42:42 +01:00
// templates
2021-06-30 02:17:54 +02:00
interface DS4ActorDataSourceDataBase {
attributes: DS4ActorDataSourceDataAttributes;
traits: DS4ActorDataSourceDataTraits;
combatValues: DS4ActorDataSourceDataCombatValues;
2021-02-05 03:42:42 +01:00
}
2021-06-30 02:17:54 +02:00
type DS4ActorDataSourceDataAttributes = { [Key in keyof typeof DS4.i18n.attributes]: ModifiableDataBase<number> };
2021-06-30 02:17:54 +02:00
type Attribute = keyof DS4ActorDataSourceDataAttributes;
export function isAttribute(value: unknown): value is Attribute {
return (Object.keys(DS4.i18n.attributes) as Array<unknown>).includes(value);
2020-12-28 15:51:00 +01:00
}
2021-06-30 02:17:54 +02:00
type DS4ActorDataSourceDataTraits = { [Key in keyof typeof DS4.i18n.traits]: ModifiableDataBase<number> };
2021-06-30 02:17:54 +02:00
type Trait = keyof DS4ActorDataSourceDataTraits;
export function isTrait(value: unknown): value is Trait {
return (Object.keys(DS4.i18n.traits) as Array<unknown>).includes(value);
}
2021-06-30 02:17:54 +02:00
type DS4ActorDataSourceDataCombatValues = {
[Key in keyof typeof DS4.i18n.combatValues]: Key extends "hitPoints"
? ResourceData<number>
: ModifiableData<number>;
};
2021-06-30 02:17:54 +02:00
type CombatValue = keyof DS4ActorDataSourceDataCombatValues;
export function isCombatValue(value: string): value is CombatValue {
return (Object.keys(DS4.i18n.combatValues) as Array<unknown>).includes(value);
}
// types
2021-06-30 02:17:54 +02:00
interface DS4CreatureDataSourceData extends DS4ActorDataSourceDataBase {
baseInfo: DS4CreatureDataSourceDataBaseInfo;
}
export interface DS4CreatureDataSourceDataBaseInfo {
loot: string;
foeFactor: number;
creatureType: CreatureType;
sizeCategory: SizeCategory;
experiencePoints: number;
description: string;
}
type CreatureType = keyof typeof DS4.i18n.creatureTypes;
type SizeCategory = keyof typeof DS4.i18n.creatureSizeCategories;
interface DS4CharacterDataSourceData extends DS4ActorDataSourceDataBase {
baseInfo: DS4CharacterDataSourceDataBaseInfo;
progression: DS4CharacterDataSourceDataProgression;
profile: DS4CharacterDataSourceDataProfile;
currency: DS4CharacterDataSourceDataCurrency;
slayerPoints: DS4CharacterDataSourceDataSlayerPoints;
}
2021-06-30 02:17:54 +02:00
export interface DS4CharacterDataSourceDataBaseInfo {
race: string;
class: string;
heroClass: string;
2021-01-03 20:37:30 +01:00
culture: string;
}
2021-06-30 02:17:54 +02:00
export interface DS4CharacterDataSourceDataProgression {
level: number;
experiencePoints: number;
2020-12-30 21:34:12 +01:00
talentPoints: UsableResource<number>;
progressPoints: UsableResource<number>;
2020-12-28 15:51:00 +01:00
}
2021-01-03 20:37:30 +01:00
2021-06-30 02:17:54 +02:00
export interface DS4CharacterDataSourceDataProfile {
2021-01-10 02:05:30 +01:00
biography: string;
2021-01-03 20:37:30 +01:00
gender: string;
birthday: string;
birthplace: string;
age: number;
height: number;
hairColor: string;
weight: number;
eyeColor: string;
specialCharacteristics: string;
}
2021-01-10 19:32:10 +01:00
2021-06-30 02:17:54 +02:00
export interface DS4CharacterDataSourceDataCurrency {
2021-01-10 19:32:10 +01:00
gold: number;
silver: number;
copper: number;
}
2021-06-30 02:17:54 +02:00
export interface DS4CharacterDataSourceDataSlayerPoints {
2021-05-13 15:41:00 +02:00
value: number;
}