Make the multi-turn indicator work fully
This commit is contained in:
parent
c549a59c13
commit
e1be6675e0
6 changed files with 76 additions and 28 deletions
|
|
@ -48,7 +48,7 @@ export class RipCryptCombat extends Combat {
|
|||
|
||||
const turn = this.turn ?? -1;
|
||||
|
||||
const groupKey = this.combatant.groupKey;
|
||||
const groupKey = this.turns[turn]?.groupKey;
|
||||
|
||||
// Determine the next turn number
|
||||
let nextTurn = null;
|
||||
|
|
@ -88,6 +88,14 @@ export class RipCryptCombat extends Combat {
|
|||
}
|
||||
}
|
||||
|
||||
if (previousTurn < 0) {
|
||||
if (this.round === 1) {
|
||||
this.round = 0;
|
||||
return this;
|
||||
};
|
||||
return this.previousRound()
|
||||
}
|
||||
|
||||
const advanceTime = this.getTimeDelta(this.round, this.turn, this.round, previousTurn);
|
||||
|
||||
// Update the document, passing data through a hook first
|
||||
|
|
@ -104,8 +112,6 @@ export class RipCryptCombat extends Combat {
|
|||
* @internal
|
||||
*/
|
||||
_updateTurnMarkers() {
|
||||
return super._updateTurnMarkers();
|
||||
/* eslint-disable no-unreachable */
|
||||
if (!canvas.ready) { return };
|
||||
|
||||
const tokenGroup = this.combatant?.groupKey;
|
||||
|
|
@ -118,15 +124,21 @@ export class RipCryptCombat extends Combat {
|
|||
|
||||
if (!this.active) { return };
|
||||
const currentToken = this.combatant?.token?._object;
|
||||
console.log(this.combatant.token._object)
|
||||
if (!tokenGroup && currentToken) {
|
||||
currentToken.renderFlags.set({refreshTurnMarker: true});
|
||||
} else {
|
||||
for (const combatant of this.groups.get(tokenGroup)) {
|
||||
console.log(combatant.token._object);
|
||||
combatant.token._object.renderFlags.set({ refreshTurnMarker: true });
|
||||
const group = this.groups.get(tokenGroup) ?? [];
|
||||
for (const combatant of group) {
|
||||
combatant.token?._object?.renderFlags.set({ refreshTurnMarker: true });
|
||||
}
|
||||
}
|
||||
/* eslint-enable no-unreachable */
|
||||
}
|
||||
|
||||
async _manageTurnEvents() {
|
||||
try {
|
||||
await super._manageTurnEvents();
|
||||
} catch {
|
||||
this._updateTurnMarkers();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { distanceBetweenFates } from "../utils/distanceBetweenFates.mjs";
|
|||
export class RipCryptCombatant extends Combatant {
|
||||
|
||||
get disposition() {
|
||||
switch (this.token.disposition) {
|
||||
switch (this.token?.disposition) {
|
||||
case CONST.TOKEN_DISPOSITIONS.HOSTILE:
|
||||
return `hostile`;
|
||||
case CONST.TOKEN_DISPOSITIONS.FRIENDLY:
|
||||
|
|
@ -12,6 +12,10 @@ export class RipCryptCombatant extends Combatant {
|
|||
return `unknown`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by the Combat tracker to order combatants according to their
|
||||
* fate path and the coin flip.
|
||||
*/
|
||||
get dynamicInitiative() {
|
||||
let total = 0;
|
||||
|
||||
|
|
@ -21,13 +25,11 @@ export class RipCryptCombatant extends Combatant {
|
|||
|
||||
const whoFirst = game.settings.get(`ripcrypt`, `whoFirst`);
|
||||
const disposition = this.disposition;
|
||||
if (whoFirst) {
|
||||
if (disposition === `unknown`) {
|
||||
total += 0.25;
|
||||
} else if (whoFirst !== disposition) {
|
||||
total += 0.5;
|
||||
};
|
||||
}
|
||||
if (disposition === `unknown`) {
|
||||
total += 0.25;
|
||||
} else if (whoFirst && whoFirst !== disposition) {
|
||||
total += 0.5;
|
||||
};
|
||||
|
||||
return total;
|
||||
};
|
||||
|
|
@ -39,16 +41,20 @@ export class RipCryptCombatant extends Combatant {
|
|||
if (!path) { return null };
|
||||
|
||||
// Token Disposition (group into: friendlies, unknown, hostiles)
|
||||
let disposition = `unknown`;
|
||||
switch (this.token.disposition) {
|
||||
case CONST.TOKEN_DISPOSITIONS.HOSTILE:
|
||||
disposition = `hostile`;
|
||||
break;
|
||||
case CONST.TOKEN_DISPOSITIONS.FRIENDLY:
|
||||
disposition = `friendly`;
|
||||
break;
|
||||
};
|
||||
let disposition = this.disposition;
|
||||
|
||||
return `${path}:${disposition}`;
|
||||
};
|
||||
|
||||
_onCreate() {
|
||||
if (this.token) {
|
||||
this.token._object._refreshTurnMarker();
|
||||
};
|
||||
};
|
||||
|
||||
_onDelete() {
|
||||
if (this.token) {
|
||||
this.token._object._refreshTurnMarker();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
27
module/documents/token.mjs
Normal file
27
module/documents/token.mjs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const { TokenTurnMarker } = foundry.canvas.placeables.tokens;
|
||||
|
||||
export class RipCryptToken extends Token {
|
||||
_refreshTurnMarker() {
|
||||
// Should a Turn Marker be active?
|
||||
const {turnMarker} = this.document;
|
||||
const markersEnabled = CONFIG.Combat.settings.turnMarker.enabled
|
||||
&& (turnMarker.mode !== CONST.TOKEN_TURN_MARKER_MODES.DISABLED);
|
||||
const combatant = game.combat?.active ? game.combat.combatant : null;
|
||||
const isTurn = combatant && (combatant.groupKey === this.combatant?.groupKey);
|
||||
const isDefeated = combatant && combatant.isDefeated;
|
||||
const markerActive = markersEnabled && isTurn && !isDefeated;
|
||||
|
||||
// Activate a Turn Marker
|
||||
if ( markerActive ) {
|
||||
if ( !this.turnMarker ) {
|
||||
this.turnMarker = this.addChildAt(new TokenTurnMarker(this), 0);
|
||||
};
|
||||
canvas.tokens.turnMarkers.add(this);
|
||||
this.turnMarker.draw();
|
||||
} else if ( this.turnMarker ) {
|
||||
canvas.tokens.turnMarkers.delete(this);
|
||||
this.turnMarker.destroy();
|
||||
this.turnMarker = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue