Skip to content

Commit

Permalink
Merge branch 'feat/editable-character-sheet' into the-metalworks#12-a…
Browse files Browse the repository at this point in the history
…ncestry-sheets
  • Loading branch information
zithith authored Sep 2, 2024
2 parents 50e6797 + 2a3ad84 commit 077db34
Show file tree
Hide file tree
Showing 83 changed files with 5,257 additions and 932 deletions.
11 changes: 10 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ export default tseslint.config(
'rollup.config.js',
'commitlint.config.js',
'lint-staged-config.mjs',
'scripts/',
],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
rules: {
'@typescript-eslint/no-namespace': 'off'
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-base-to-string': 'off',
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_\\d{0,3}$",
}
]
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
allowDefaultProject: ['*.js'],
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default {
targets: [
{ src: 'src/system.json', dest: 'build' },
{ src: 'src/templates/**/*.hbs', dest: 'build/' },
{ src: 'src/lang/*.json', dest: 'build/' }
{ src: 'src/lang/*.json', dest: 'build/' },
{ src: 'src/assets/**/*', dest: 'build/' }
],
flatten: false
}),
Expand Down
3 changes: 3 additions & 0 deletions src/assets/icons/dice/d20white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/ui/equip-1h-bottom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/ui/equip-1h-top.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/ui/equip-2h.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions src/declarations/foundry/common/abstract/fields.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ declare namespace foundry {
dropInvalidEmbedded?: boolean;
}

interface DataModelValidationFailure {}

type DataFieldValidator = (
value: any,
options?: DataFieldValidationOptions,
Expand Down Expand Up @@ -75,10 +77,137 @@ declare namespace foundry {
> {
constructor(option?: Options, context?: DataFieldContext);

/**
* The field name of this DataField instance.
* This is assigned by SchemaField#initialize.
* @internal
*/
name: string;

/**
* The initially provided options which configure the data field
*/
options: Options;

/**
* Whether this field defines part of a Document/Embedded Document hierarchy.
* @default false
*/
static hierarchical: boolean;

/**
* Does this field type contain other fields in a recursive structure?
* Examples of recursive fields are SchemaField, ArrayField, or TypeDataField
* Examples of non-recursive fields are StringField, NumberField, or ObjectField
* @default false
*/
static recursive: boolean;

/**
* Default parameters for this field type
*/
protected static get _defaults(): DataFieldOptions;

/**
* A dot-separated string representation of the field path within the parent schema.
*/
get fieldPath(): string;

/**
* Apply a function to this DataField which propagates through recursively to any contained data schema.
* @param fn The function to apply
* @param value The current value of this field
* @param options Additional options passed to the applied function
*/
apply(
fn: string | Function,
value: any,
options?: object,
): object;

/* -------------------------------------------- */
/* Field Cleaning */
/* -------------------------------------------- */

/**
* Coerce source data to ensure that it conforms to the correct data type for the field.
* Data coercion operations should be simple and synchronous as these are applied whenever a DataModel is constructed.
* For one-off cleaning of user-provided input the sanitize method should be used.
* @param value The initial value
* @param options Additional options for how the field is cleaned
*/
clean(
value: any,
options?: { partial?: boolean; source?: object },
): any;

/**
* Apply any cleaning logic specific to this DataField type.
* @param value The appropriately coerced value.
* @param options Additional options for how the field is cleaned.
*/
protected _cleanType(value: any, options?: object): any;

/**
* Attempt to retrieve a valid initial value for the DataField.
* @param data The source data object for which an initial value is required
* @returns A valid initial value
* @throws An error if there is no valid initial value defined
*/
getInitialValue(data: object): any;

/* -------------------------------------------- */
/* Field Validation */
/* -------------------------------------------- */

/**
* Validate a candidate input for this field, ensuring it meets the field requirements.
* A validation failure can be provided as a raised Error (with a string message), by returning false, or by returning
* a DataModelValidationFailure instance.
* A validator which returns true denotes that the result is certainly valid and further validations are unnecessary.
* @param value The initial value
* @param options Options which affect validation behavior
* @returns Returns a DataModelValidationFailure if a validation failure
* occurred.
*/
validate(
value: any,
options?: DataFieldValidationOptions,
): DataModelValidationFailure | void;

/**
* A default type-specific validator that can be overridden by child classes
* @param value The candidate value
* @param options Options which affect validation behavior
* @returns A boolean to indicate with certainty whether the value is
* valid, or specific DataModelValidationFailure information,
* otherwise void.
* @throws May throw a specific error if the value is not valid
*/
protected _validateType(
value: any,
options?: DataFieldValidationOptions,
): boolean | DataModelValidationFailure | void;

/* -------------------------------------------- */
/* Initialization and Serialization */
/* -------------------------------------------- */

/**
* Initialize the original source data into a mutable copy for the DataModel instance.
* @param value The source value of the field
* @param model The DataModel instance that this field belongs to
* @param options Initialization options
* @returns An initialized copy of the source data
*/
initialize(value: any, model: object, options?: object): 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;
}

class SchemaField extends DataField {
Expand Down
9 changes: 9 additions & 0 deletions src/declarations/foundry/common/abstract/validation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace foundry {
namespace data {
namespace validation {
class DataModelValidationError extends Error {
constructor(errors: Record<string, any>);
}
}
}
}
9 changes: 9 additions & 0 deletions src/declarations/foundry/common/documents/combat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace foundry {
namespace documents {
declare class BaseCombat<
Schema extends
foundry.abstract.DataSchema = foundry.abstract.DataSchema,
Parent extends Document | null = null,
> extends foundry.abstract.Document<Schema, Parent> {}
}
}
9 changes: 9 additions & 0 deletions src/declarations/foundry/common/documents/combatant.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace foundry {
namespace documents {
declare class BaseCombatant<
Schema extends
foundry.abstract.DataSchema = foundry.abstract.DataSchema,
Parent extends Document | null = null,
> extends foundry.abstract.Document<Schema, Parent> {}
}
}
36 changes: 28 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,30 @@ Hooks.once('init', async () => {
CONFIG.Item.dataModels = dataModels.item.config;
CONFIG.Item.documentClass = documents.CosmereItem;

CONFIG.Combat.documentClass = documents.CosmereCombat;
CONFIG.Combatant.documentClass = documents.CosmereCombatant;
CONFIG.ui.combat = applications.combat.CosmereCombatTracker;

Actors.unregisterSheet('core', ActorSheet);
Actors.registerSheet('cosmere-rpg', applications.actor.CharacterSheet, {
types: ['character'],
label: `${game.i18n?.localize('COSMERE.Actor.Character.Character')}`,
});
Actors.registerSheet('cosmere-rpg', applications.actor.AdversarySheet, {
types: ['adversary'],
label: `${game.i18n?.localize('COSMERE.Actor.Adversary.Adversary')}`,
});
// NOTE: Must cast to `any` as registerSheet type doesn't accept ApplicationV2 (even though it's valid to pass it)
Actors.registerSheet(
'cosmere-rpg',
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
applications.actor.CharacterSheet as any,
{
types: ['character'],
label: `${game.i18n?.localize('COSMERE.Actor.Character.Character')}`,
},
);
Actors.registerSheet(
'cosmere-rpg',
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
applications.actor.AdversarySheet as any,
{
types: ['adversary'],
label: `${game.i18n?.localize('COSMERE.Actor.Adversary.Adversary')}`,
},
);

Items.registerSheet('cosmere-rpg', applications.item.AncestrySheet, {
types: ['ancestry'],
Expand All @@ -57,4 +72,9 @@ Hooks.once('init', async () => {

// Load templates
await preloadHandlebarsTemplates();

// TEMP: This resembles a system module
(CONFIG.COSMERE.paths.types as Record<string, unknown>).radiant = {
label: 'Radiant',
};
});
Loading

0 comments on commit 077db34

Please sign in to comment.