RC-42 | Weapon | Damage
This commit is contained in:
parent
0e9218fbd3
commit
b578ecb10d
2 changed files with 16 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { optionalInteger } from "../helpers.mjs";
|
||||
import { optionalInteger, requiredInteger } from "../helpers.mjs";
|
||||
|
||||
const { fields } = foundry.data;
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ export class WeaponData extends foundry.abstract.TypeDataModel {
|
|||
short: optionalInteger(),
|
||||
long: optionalInteger(),
|
||||
}),
|
||||
damage: requiredInteger({ min: 0, initial: 0 }),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,3 +29,17 @@ export function optionalInteger({min, initial = null, max} = {}) {
|
|||
integer: true,
|
||||
});
|
||||
};
|
||||
|
||||
export function requiredInteger({ min, initial, max } = {}) {
|
||||
if (initial == null || typeof initial !== `number`) {
|
||||
throw new Error(`"initial" must be a number`);
|
||||
};
|
||||
return new fields.NumberField({
|
||||
min,
|
||||
initial,
|
||||
max,
|
||||
required: true,
|
||||
nullable: false,
|
||||
integer: true,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue