Compare commits
3 commits
753b934534
...
5d8e34ce5f
Author | SHA1 | Date | |
---|---|---|---|
5d8e34ce5f | |||
|
dbac03fbad | ||
95a595773d |
5 changed files with 37 additions and 21 deletions
|
@ -1,7 +1,8 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "es2022",
|
"module": "es2022",
|
||||||
"target": "ES2022"
|
"target": "ES2022",
|
||||||
|
"strict": true
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "dist"],
|
"exclude": ["node_modules", "dist"],
|
||||||
"include": ["src", "client", "common"]
|
"include": ["src", "client", "common"]
|
||||||
|
|
32
module.json
32
module.json
|
@ -11,23 +11,35 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"url": "https://git.f3l.de/dungeonslayers/tickwerk",
|
"url": "https://git.f3l.de/dungeonslayers/tickwerk",
|
||||||
"license": "https://git.f3l.de/dungeonslayers/tickwerk/raw/tag/1.3.3/LICENSE.md",
|
"license": "https://git.f3l.de/dungeonslayers/tickwerk/raw/tag/1.3.4/LICENSE.md",
|
||||||
"readme": "https://git.f3l.de/dungeonslayers/tickwerk/raw/tag/1.3.3/README.md",
|
"readme": "https://git.f3l.de/dungeonslayers/tickwerk/raw/tag/1.3.4/README.md",
|
||||||
"bugs": "https://git.f3l.de/dungeonslayers/tickwerk/issues",
|
"bugs": "https://git.f3l.de/dungeonslayers/tickwerk/issues",
|
||||||
"changelog": "https://git.f3l.de/dungeonslayers/tickwerk/releases/tag/1.3.3",
|
"changelog": "https://git.f3l.de/dungeonslayers/tickwerk/releases/tag/1.3.4",
|
||||||
"version": "1.3.3",
|
"version": "1.3.4",
|
||||||
"flags": {
|
"flags": {
|
||||||
"hotReload": {
|
"hotReload": {
|
||||||
"extensions": ["css", "hbs", "json"],
|
"extensions": [
|
||||||
"paths": ["templates", "css", "lang"]
|
"css",
|
||||||
|
"hbs",
|
||||||
|
"json"
|
||||||
|
],
|
||||||
|
"paths": [
|
||||||
|
"templates",
|
||||||
|
"css",
|
||||||
|
"lang"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"compatibility": {
|
"compatibility": {
|
||||||
"minimum": "10.290",
|
"minimum": "10.290",
|
||||||
"verified": "10"
|
"verified": "11"
|
||||||
},
|
},
|
||||||
"esmodules": ["tickwerk.js"],
|
"esmodules": [
|
||||||
"styles": ["styles/tickwerk.css"],
|
"tickwerk.js"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"styles/tickwerk.css"
|
||||||
|
],
|
||||||
"languages": [
|
"languages": [
|
||||||
{
|
{
|
||||||
"lang": "en",
|
"lang": "en",
|
||||||
|
@ -41,6 +53,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"manifest": "https://git.f3l.de/api/packages/dungeonslayers/generic/tickwerk/latest/module.json",
|
"manifest": "https://git.f3l.de/api/packages/dungeonslayers/generic/tickwerk/latest/module.json",
|
||||||
"download": "https://git.f3l.de/dungeonslayers/tickwerk/releases/download/1.3.3/tickwerk.zip",
|
"download": "https://git.f3l.de/dungeonslayers/tickwerk/releases/download/1.3.4/tickwerk.zip",
|
||||||
"manifestPlusVersion": "1.2.0"
|
"manifestPlusVersion": "1.2.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "tickwerk",
|
"name": "tickwerk",
|
||||||
"description": "A tick based combat system for Foundry Virtual Tabletop",
|
"description": "A tick based combat system for Foundry Virtual Tabletop",
|
||||||
"version": "1.3.3",
|
"version": "1.3.4",
|
||||||
"license": "https://git.f3l.de/dungeonslayers/tickwerk#licensing",
|
"license": "https://git.f3l.de/dungeonslayers/tickwerk#licensing",
|
||||||
"homepage": "https://git.f3l.de/dungeonslayers/tickwerk",
|
"homepage": "https://git.f3l.de/dungeonslayers/tickwerk",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -112,14 +112,16 @@ const CombatantMixin = (BaseCombatant) => {
|
||||||
* @param {object} data The data of the creation / update
|
* @param {object} data The data of the creation / update
|
||||||
*/
|
*/
|
||||||
async #updateTiebreakerData(data) {
|
async #updateTiebreakerData(data) {
|
||||||
if ('initiative' in data) {
|
const waiting = data.flags?.[packageId]?.waiting;
|
||||||
|
if ('initiative' in data || waiting !== undefined) {
|
||||||
|
const newInitiative = data.initiative ?? this.initiative;
|
||||||
const combatantsWithSameTickValue =
|
const combatantsWithSameTickValue =
|
||||||
this.parent?.combatants.filter((combatant) => {
|
this.parent?.combatants.filter((combatant) => {
|
||||||
const otherInitiative =
|
const otherInitiative =
|
||||||
combatant._newInitiative !== undefined ? combatant._newInitiative : combatant.initiative;
|
combatant._newInitiative !== undefined ? combatant._newInitiative : combatant.initiative;
|
||||||
return otherInitiative === data.initiative;
|
return otherInitiative === newInitiative && combatant !== this;
|
||||||
}) ?? [];
|
}) ?? [];
|
||||||
const tiebreaker = await this.#getTiebreaker(combatantsWithSameTickValue);
|
const tiebreaker = await this.#getTiebreaker(combatantsWithSameTickValue, waiting);
|
||||||
foundry.utils.setProperty(data, `flags.${packageId}.tiebreaker`, tiebreaker);
|
foundry.utils.setProperty(data, `flags.${packageId}.tiebreaker`, tiebreaker);
|
||||||
this._newInitiative = data.initiative;
|
this._newInitiative = data.initiative;
|
||||||
this._newTiebreaker = tiebreaker;
|
this._newTiebreaker = tiebreaker;
|
||||||
|
@ -129,11 +131,12 @@ const CombatantMixin = (BaseCombatant) => {
|
||||||
/**
|
/**
|
||||||
* Get a tiebreaker between this combatant and the given other combatants.
|
* Get a tiebreaker between this combatant and the given other combatants.
|
||||||
* @param {TickwerkCombatant[]} combatants The other combatants among which to find a tiebreaker
|
* @param {TickwerkCombatant[]} combatants The other combatants among which to find a tiebreaker
|
||||||
|
* @param {boolean | undefined} waiting The change of the waiting state of the combatanmt
|
||||||
* @returns {Promise<number>} A promise that resolves to the tiebreaker
|
* @returns {Promise<number>} A promise that resolves to the tiebreaker
|
||||||
*/
|
*/
|
||||||
async #getTiebreaker(combatants) {
|
async #getTiebreaker(combatants, waiting) {
|
||||||
const getTiebreaker = CONFIG.tickwerk?.getTiebreaker ?? defaultGetTiebreaker;
|
const getTiebreaker = CONFIG.tickwerk?.getTiebreaker ?? defaultGetTiebreaker;
|
||||||
return getTiebreaker(this, combatants);
|
return getTiebreaker(this, combatants, waiting);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
|
@ -179,14 +182,14 @@ const CombatantMixin = (BaseCombatant) => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function to get a tiebreaker for a combatant
|
* A function to get a tiebreaker for a combatant
|
||||||
* @typedef {(combatant: TickwerkCombatant, combatants: TickwerkCombatant[]) => Promise<number>} GetTiebreaker
|
* @typedef {(combatant: TickwerkCombatant, combatants: TickwerkCombatant[], waiting: boolean | undefined) => Promise<number>} GetTiebreaker
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation to get a tiebreaker for a combatant.
|
* Default implementation to get a tiebreaker for a combatant.
|
||||||
* @type {GetTiebreaker}
|
* @type {GetTiebreaker}
|
||||||
*/
|
*/
|
||||||
const defaultGetTiebreaker = async (combatant, combatants) => {
|
export const defaultGetTiebreaker = async (combatant, combatants) => {
|
||||||
if (combatants.length === 0) return 0;
|
if (combatants.length === 0) return 0;
|
||||||
const tiebreakers = combatants.map((combatant) => {
|
const tiebreakers = combatants.map((combatant) => {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const registerDS4SpecificFunctionality = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {import("../data/documents/combatant").GetTiebreaker} */
|
/** @type {import("../data/documents/combatant").GetTiebreaker} */
|
||||||
const getTiebreaker = async (combatant, combatants) => {
|
const getTiebreaker = async (combatant, combatants, waiting) => {
|
||||||
if (combatants.length === 0) return 0;
|
if (combatants.length === 0) return 0;
|
||||||
|
|
||||||
/** @type {number[]} */
|
/** @type {number[]} */
|
||||||
|
@ -26,7 +26,7 @@ const getTiebreaker = async (combatant, combatants) => {
|
||||||
|
|
||||||
for (const other of combatants) {
|
for (const other of combatants) {
|
||||||
const tiebreaker = other._newTiebreaker ?? other.getFlag(packageId, 'tiebreaker') ?? 0;
|
const tiebreaker = other._newTiebreaker ?? other.getFlag(packageId, 'tiebreaker') ?? 0;
|
||||||
if (getInitiative(other) > getInitiative(combatant)) {
|
if (getInitiative(other) > getInitiative(combatant) || waiting === false) {
|
||||||
lowerBounds.push(tiebreaker);
|
lowerBounds.push(tiebreaker);
|
||||||
} else if (getInitiative(other) < getInitiative(combatant)) {
|
} else if (getInitiative(other) < getInitiative(combatant)) {
|
||||||
upperBounds.push(tiebreaker);
|
upperBounds.push(tiebreaker);
|
||||||
|
|
Loading…
Reference in a new issue