Skip to content

Commit

Permalink
feat: add support for powers (e.g. surges) and path skills (#124)
Browse files Browse the repository at this point in the history
* feat: add Goal & Power item documents and add support for linked skills to paths

* feat(talents): add grant rules to be executed upon obtaining the talent

* chore: make grant rules deletable

* feat(talents): add functionality to execute grant rules for talents

* chore(goal): refactor goal onCompletion.grants to rewards

* feat(goals): implement automatic reward granting upon goal completion

* feat(actor): add unlocked field to non-core skills

* feat(character sheet): Show path linked skills beside the path

* feat(character sheet): add power type sections to actions list

* fix(multi value select component): fix issue causing selected values to lose labels

* fix(item rewards): fix issue causing item goal rewards to grant id-ed items the actor already possesses

* fix(talents & goals): fix issue causing a duplicate goal to be added when the granting talent is removed and re-added

* feat(powers): make it so by default powers use the skill matching their id

* feat(actor): add check to block adding a power whose id matches a power already present on the actor

* feat(powers): change none power type label and make untyped powers show up in actions list under "powers"
  • Loading branch information
stanavdb authored Nov 4, 2024
1 parent 58993b8 commit 41fec09
Show file tree
Hide file tree
Showing 89 changed files with 3,842 additions and 567 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default tseslint.config(
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'no-unexpected-multiline': 'off',
},
languageOptions: {
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ declare function _ClientDocumentMixin<
>(base: BaseClass): Mixin<BaseClass, typeof ClientDocument>;

declare class ClientDocument {
readonly uuid: string;

/**
* A collection of Application instances which should be re-rendered whenever this document is updated.
* The keys of this object are the application ids and the values are Application instances. Each
Expand Down
18 changes: 9 additions & 9 deletions src/declarations/foundry/client/data/documents/actor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ declare class Actor<
/**
* Handle how changes to a Token attribute bar are applied to the Actor.
* This allows for game systems to override this behavior and deploy special logic.
* @param {string} attribute The attribute path
* @param {number} value The target attribute value
* @param {boolean} isDelta Whether the number represents a relative change (true) or an absolute change (false)
* @param {boolean} isBar Whether the new value is part of an attribute bar, or just a direct value
* @returns {Promise<documents.Actor>} The updated Actor document
* @param attribute The attribute path
* @param value The target attribute value
* @param isDelta Whether the number represents a relative change (true) or an absolute change (false)
* @param isBar Whether the new value is part of an attribute bar, or just a direct value
* @returns The updated Actor document
*/
public async modifyTokenAttribute(
attribute,
value,
isDelta,
isBar,
attribute: string,
value: number,
isDelta: boolean,
isBar: boolean,
): Promise<Actor | undefined>;
}
33 changes: 31 additions & 2 deletions src/declarations/foundry/common/abstract/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,35 @@ namespace foundry {
operation: DatabaseCreateOperation,
user: documents.BaseUser,
): Promise<void>;

/* --- Database Update Operations --- */

/**
* Pre-process an update operation for a single Document instance. Pre-operation events only occur for the client
* which requested the operation.
*
* @param changes The candidate changes to the Document
* @param options Additional options which modify the update request
* @param user The User requesting the document update
* @returns A return value of false indicates the update operation should be cancelled.
* @internal
*/
async _preUpdate(
changes: object,
options: object,
user: documents.BaseUser,
): Promise<boolean | void>;

/**
* Post-process an update operation for a single Document instance. Post-operation events occur for all connected
* clients.
*
* @param changed The differential data that was changed relative to the documents prior values
* @param options Additional options which modify the update request
* @param userId The id of the User requesting the document update
* @internal
*/
_onUpdate(changed: object, options: object, userId: string);
}

interface DataValidationOptions {
Expand Down Expand Up @@ -755,7 +784,7 @@ namespace foundry {
* @param options Options provided to the model constructor
* @returns Migrated and cleaned source data which will be stored to the model instance
*/
_initializeSource(
protected _initializeSource(
data: object | DataModel,
options?: object,
): object;
Expand All @@ -773,7 +802,7 @@ namespace foundry {
* This mirrors the workflow of SchemaField#initialize but with some added functionality.
* @param options Options provided to the model constructor
*/
_initialize(options?: object);
protected _initialize(options?: object);

/**
* Reset the state of this data instance back to mirror the contained source data, erasing any changes.
Expand Down
14 changes: 14 additions & 0 deletions src/declarations/foundry/common/abstract/fields.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,26 @@ declare namespace foundry {
*/
initialize(value: any, model: object, options?: object): any;

/**
* Export the current value of the field into a serializable object.
* @param value The initialized value of the field
* @returns An exported representation of the field
*/
toObject(value: any): any;

/**
* Recursively traverse a schema and retrieve a field specification by a given path
* @param path The field path as an array of strings
* @internal
*/
_getField(path: string[]): DataField;

/**
* Cast a non-default value to ensure it is the correct type for the field
* @param value The provided non-default value
* @returns The standardized value
*/
protected _cast(value: any): any;
}

class SchemaField extends DataField {
Expand Down
85 changes: 85 additions & 0 deletions src/declarations/foundry/common/abstract/validation.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,91 @@
declare namespace foundry {
namespace data {
namespace validation {
namespace DataModelValidationFailure {
interface Config {
/**
* The value that failed validation for this field.
*/
invalidValue?: any;

/**
* The value it was replaced by, if any.
*/
fallback?: any;

/**
* Whether the value was dropped from some parent collection.
* @default true
*/
dropped?: boolean;

/**
* The validation error message.
*/
message?: string;

/**
* Whether this failure was unresolved
* @default false
*/
unresolved?: boolean;
}

interface ElementValidationFailure {
/**
* Either the element's index or some other identifier for it.
*/
id: string | number;

/**
* Optionally a user-friendly name for the element.
*/
name?: string;

/**
* The element's validation failure.
*/
failure: DataModelValidationFailure;
}
}

class DataModelValidationFailure {
/**
* The value that failed validation for this field.
*/
public invalidValue?: any;

/**
* The value it was replaced by, if any.
*/
public fallback?: any;

/**
* Whether the value was dropped from some parent collection.
* @defaultValue true
*/
public dropped?: boolean;

/**
* The validation error message.
*/
public message?: string;

/**
* If this field contains other fields that are validated
* as part of its validation, their results are recorded here.
*/
public fields: Record<string, DataModelValidationFailure>;

/**
* If this field contains a list of elements that are validated
* as part of its validation, their results are recorded here.
*/
public elements: ElementValidationFailure[];

constructor(config?: DataModelValidationFailure.Config);
}

class DataModelValidationError extends Error {
constructor(errors: Record<string, any>);
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Hooks.once('init', async () => {
registerItemSheet(ItemType.Talent, applications.item.TalentItemSheet);
registerItemSheet(ItemType.Equipment, applications.item.EquipmentItemSheet);
registerItemSheet(ItemType.Weapon, applications.item.WeaponItemSheet);
registerItemSheet(ItemType.Goal, applications.item.GoalItemSheet);
registerItemSheet(ItemType.Power, applications.item.PowerItemSheet);

CONFIG.Dice.types.push(dice.PlotDie);
CONFIG.Dice.terms.p = dice.PlotDie;
Expand Down
Loading

0 comments on commit 41fec09

Please sign in to comment.