Skip to content

Commit

Permalink
I'm honestly not sure if I'm making progress or blowing everything up
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunomiac committed Jan 28, 2024
1 parent 2c68044 commit 0bfff8e
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 307 deletions.
6 changes: 4 additions & 2 deletions ts/@types/blades-roll.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ declare global {

namespace BladesRoll {

export interface Config extends Partial<BladesTargetLink.Config> {
interface UnlinkedConfig {
rollType?: RollType,
rollSubType?: RollSubType,
rollUserID?: IDString,
Expand Down Expand Up @@ -81,6 +81,8 @@ declare global {
userPermissions?: Record<IDString, RollPermissions>
}

export type Config = UnlinkedConfig & BladesTargetLink.Config;

export interface Schema extends Omit<Config, "rollClockKey"|"rollPrimaryData"|"rollOppData"|"rollParticipantData"> {
rollPrompt?: string;

Expand Down Expand Up @@ -230,7 +232,7 @@ declare global {
rollPrimaryType: PrimaryDocType,
rollPrimaryImg: string,

rollModsData: RollModData[],
rollModsSchemaSet: RollModData[],
rollFactors: Partial<Record<Factor,FactorData>>

applyHarm?(amount: num, name: num)
Expand Down
34 changes: 31 additions & 3 deletions ts/@types/blades-target-link.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,48 @@ declare global {
export type StaticThisContext<Schema> = typeof BladesTargetLink
& (new (data: Data & Schema) => BladesTargetLink & Subclass<Schema>);

export type Config = {
export type LinkData = {
targetID: UUIDString,
targetKey: TargetKey
} | {
targetID: UUIDString,
targetFlagKey: TargetFlagKey
};

export type Data = {id: IDString} & LinkData;

export type Config = ({
target: IDString|UUIDString|BladesDoc|BladesChat|User
} | {
targetID: IDString|UUIDString
}) & ({
targetKey: TargetKey
} | {
targetFlagKey: TargetFlagKey
});

export type PartialConfig = {
target?: IDString|UUIDString|BladesDoc|BladesChat|User,
targetID?: IDString|UUIDString,
targetKey?: TargetKey,
targetFlagKey?: TargetFlagKey
}
};

export type Data = {
export type PartialData = {
id: IDString,
targetID: UUIDString,
targetKey?: TargetKey,
targetFlagKey?: TargetFlagKey
}


// export type Config = {
// target?: IDString|UUIDString|BladesDoc|BladesChat|User,
// targetID?: IDString|UUIDString,
// targetKey?: TargetKey,
// targetFlagKey?: TargetFlagKey
// }

export type Instance = Data & {
target: BladesDoc|BladesChat|User
}
Expand Down
2 changes: 1 addition & 1 deletion ts/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ declare global {
eunoblades: EunoBlades.Game
}
declare interface User {
_id: string,
id: IDString,
flags: {
["eunos-blades"]?: Record<string,any>
}
Expand Down
4 changes: 2 additions & 2 deletions ts/BladesActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,8 @@ class BladesActor extends Actor implements BladesDocument<Actor> {
// #endregion

// #region BladesRoll Implementation ~
get rollModsData(): BladesRollMod.Schema[] {
return BladesRollMod.ParseDocRollMods(this);
get rollModsSchemaSet(): BladesRollMod.Schema[] {
return BladesRollMod.ParseDocModsToSchemaSet(this);
}

get rollFactors(): Partial<Record<Factor, BladesRoll.FactorData>> {
Expand Down
6 changes: 2 additions & 4 deletions ts/BladesItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@ class BladesItem extends Item implements BladesDocument<Item>,

get rollPrimaryImg() { return this.img; }

get rollModsData(): BladesRollMod.Schema[] {
// Const rollModData = BladesRollMod.ParseDocRollMods(this);
get rollModsSchemaSet(): BladesRollMod.Schema[] {
// Add roll mods from COHORT harm

return BladesRollMod.ParseDocRollMods(this);
return BladesRollMod.ParseDocModsToSchemaSet(this);
}

async applyHarm(amount: number, _name: string) {
Expand Down
4 changes: 2 additions & 2 deletions ts/blades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class GlobalGetter {
rollPrimaryName: pc.name,
rollPrimaryType: pc.type,
rollPrimaryImg: pc.img,
rollModsData: pc.rollModsData,
rollModsData: pc.rollModsSchemaSet,
rollFactors: pc.rollFactors,
applyHarm: pc.applyHarm,
applyWorsePosition: pc.applyWorsePosition
Expand Down Expand Up @@ -501,7 +501,7 @@ class GlobalGetter {
rollPrimaryName: pc.name,
rollPrimaryType: pc.type,
rollPrimaryImg: pc.img,
rollModsData: pc.rollModsData,
rollModsData: pc.rollModsSchemaSet,
rollFactors: pc.rollFactors,
applyHarm: pc.applyHarm,
applyWorsePosition: pc.applyWorsePosition
Expand Down
31 changes: 22 additions & 9 deletions ts/classes/BladesClocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export type ClockKeyElems$ = {
};

function isElemPosData(obj: unknown): obj is ElemPosData {
if (!U.isList(obj)) { return false; }
return typeof obj.x === "number" && typeof obj.y === "number" && typeof obj.width === "number" && typeof obj.height === "number";
return U.isList(obj)
&& typeof obj.x === "number"
&& typeof obj.y === "number"
&& typeof obj.width === "number"
&& typeof obj.height === "number";
}

class BladesClockKey extends BladesTargetLink<BladesClockKey.Schema> implements BladesClockKey.Subclass {
Expand Down Expand Up @@ -368,16 +371,26 @@ class BladesClockKey extends BladesTargetLink<BladesClockKey.Schema> implements
if (indexOverride !== undefined && indexOverride < 0) {throw new Error("Cannot add a clock with a negative index.");}

// Remove target so it doesn't conflict with key's targetID
delete config.target;
// delete config.target;

const {target, targetID, targetKey, targetFlagKey, ...partialSchema} = config;

const linkData: BladesTargetLink.LinkData = this.targetKey
? {
targetID: this.targetID,
targetKey: `${this.targetKey}.${this.id}.clocksData` as TargetKey
}
: {
targetID: this.targetID,
targetFlagKey: `${this.targetFlagKey}.${this.id}.clocksData` as TargetFlagKey
};

// Derive clock's targetID and targetKey/targetFlagKey from key's values
config.targetID = this.targetID;
data.targetID = this.targetID;
if (this.targetKey) {
config.targetKey = `${this.targetKey}.${this.id}.clocksData` as TargetKey;
delete config.targetFlagKey;
data.targetKey = `${this.targetKey}.${this.id}.clocksData` as TargetKey;
} else if (this.targetFlagKey) {
config.targetFlagKey = `${this.targetFlagKey}.${this.id}.clocksData` as TargetFlagKey;
delete config.targetKey;
data.targetFlagKey = `${this.targetFlagKey}.${this.id}.clocksData` as TargetFlagKey;
}

// Assign 'parentKeyID' and 'index'
Expand All @@ -386,7 +399,7 @@ class BladesClockKey extends BladesTargetLink<BladesClockKey.Schema> implements

// Parse config to full data object
return BladesClock.ApplySchemaDefaults(
BladesClock.ParseConfig(config as BladesClock.Config)
BladesClock.ParseConfigToData(config as BladesClock.Config)
);
}

Expand Down
4 changes: 4 additions & 0 deletions ts/classes/BladesConsequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class BladesConsequence extends BladesTargetLink<BladesConsequence.Data> {
constructor(
data: Partial<BladesConsequence.Data>,
parentCsq?: BladesConsequence
)
constructor(
data: BladesTargetLink.Data & Partial<BladesConsequence.Data> | Partial<BladesConsequence.Data>,
parentCsq?: BladesConsequence
) {
const {id, targetID, targetKey, targetFlagKey} = {...parentCsq ?? {}, ...data} as BladesTargetLink.Data;
super({id, targetID, targetKey, targetFlagKey});
Expand Down
Loading

0 comments on commit 0bfff8e

Please sign in to comment.