Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/abilities/Dark-Priest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ export default (G: Game) => {

// Callback function to queryCreature
materialize: function (creature: CreatureType) {
// Prevent double-click / re-entrancy while already picking a location.
if (G.UI.materializeInProgress) {
return;
}
G.UI.materializeInProgress = true;

const ability = this;
const dpriest = this.creature;

Expand All @@ -266,6 +272,7 @@ export default (G: Game) => {
{ materializationSickness: creatureHasMaterializationSickness },
);
const fullCrea = new Creature(crea, G);
const tempCreatureId = fullCrea.id;
// Don't allow temporary Creature to take up space
fullCrea.cleanHex();
// Make temporary Creature invisible
Expand Down Expand Up @@ -296,6 +303,13 @@ export default (G: Game) => {
G.grid.previewCreature(hex.pos, crea, ability.creature.player);
},
fnOnCancel: function () {
// Cleanup temp creature + clear guard so user can try again.
const temp = G.creatures[tempCreatureId];
if (temp && temp.temp) {
temp.destroy();
G.updateQueueDisplay();
}
G.UI.materializeInProgress = false;
G.activeCreature.queryMove();
},
fnOnConfirm: function (...args) {
Expand All @@ -304,6 +318,7 @@ export default (G: Game) => {
args: {
creature: creature,
cost: crea.size - 0 + ((crea.level as number) - 0),
tempCreatureId,
}, // OptionalArgs
size: crea.size,
flipped: dpriest.player.flipped,
Expand All @@ -327,6 +342,16 @@ export default (G: Game) => {

ability.end(false, true);

// Cleanup the temporary creature created during targeting.
if (args && args.tempCreatureId) {
const temp = G.creatures[args.tempCreatureId];
if (temp && temp.temp) {
temp.destroy();
G.updateQueueDisplay();
}
}
G.UI.materializeInProgress = false;

ability.creature.player.summon(creature, pos);
ability.creature.queryMove();
},
Expand Down
6 changes: 6 additions & 0 deletions src/ui/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export class UI {
queueAnimSpeed: number;
dashAnimSpeed: number;
materializeToggled: boolean;
/**
* Guard to prevent re-entrancy in Dark Priest materialization flow.
* (e.g. double-clicking the materialize button while already picking a hex)
*/
materializeInProgress: boolean;
glowInterval: ReturnType<typeof setInterval>;
selectedCreatureObj: Creature;
activeAbility: boolean;
Expand Down Expand Up @@ -665,6 +670,7 @@ export class UI {
this.dashAnimSpeed = 250; // ms

this.materializeToggled = false;
this.materializeInProgress = false;
this.dashopen = false;

this.glowInterval = setInterval(() => {
Expand Down
Loading