Skip to content

Commit d630281

Browse files
committed
chore: Small restructure in Modal system
1 parent c97c9bc commit d630281

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

client/src/game/systems/modals/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { System } from "..";
77
import { modalState } from "./state";
88
import type { FullModal, IndexedModal, Modal, ModalIndex } from "./types";
99

10-
const { mutableReactive: $ } = modalState;
10+
const { mutableReactive: $, raw } = modalState;
1111

1212
function isComponent(x: Component | { component: Component }): x is Component {
1313
return !("component" in x);
@@ -36,13 +36,14 @@ class ModalSystem implements System {
3636
}
3737

3838
focus(index: ModalIndex): void {
39-
const orderId = modalState.raw.modalOrder.findIndex((m) => m === index);
39+
if (raw.modalOrder.at(-1) === index) return;
40+
const orderId = raw.modalOrder.findIndex((m) => m === index);
4041
if (orderId === undefined) {
4142
console.log("Error in modal focussing");
4243
return;
4344
}
4445
// Doing it like this prevents a double update
45-
$.modalOrder = [...modalState.raw.modalOrder.filter((m) => m !== index), index];
46+
$.modalOrder = [...raw.modalOrder.filter((m) => m !== index), index];
4647
$.openModals.add(index);
4748
}
4849

@@ -53,15 +54,15 @@ class ModalSystem implements System {
5354
$.openModals.delete(modalId);
5455
if (remove && modalId >= extraStartIndex) {
5556
delete $.extraModals[modalId - extraStartIndex];
56-
$.modalOrder.splice(modalState.raw.modalOrder.indexOf(modalId), 1);
57+
$.modalOrder.splice(raw.modalOrder.indexOf(modalId), 1);
5758
}
5859
}
5960

6061
addModal(modal: FullModal): ModalIndex {
6162
// First see if we can fill up a hole
62-
let extraIndex = modalState.raw.extraModals.findIndex((m) => m === undefined);
63+
let extraIndex = raw.extraModals.findIndex((m) => m === undefined);
6364
if (extraIndex === -1) {
64-
extraIndex = modalState.raw.extraModals.length;
65+
extraIndex = raw.extraModals.length;
6566
}
6667
const modalIndex = (extraIndex + modalState.readonly.fixedModals.length) as ModalIndex;
6768
const indexedModal = { ...modal, props: { ...modal.props, modalIndex } };

0 commit comments

Comments
 (0)