Skip to content

Commit

Permalink
feat(manager): add typeahead to "Lancer ID" field
Browse files Browse the repository at this point in the history
Add native browser typeahead to the "Lancer ID" field in the effects
manager. This reduces the need to reference the README when making
custom FX for special LIDs.

Note that we do not scan the user's game for every available LID, as
this could be very slow, and would mean loading every compendium. We
approximate the list by using the keys in our `weaponEffects` map
instead.
  • Loading branch information
cirrahn committed Jul 25, 2024
1 parent f5b30f8 commit 5eaa1eb
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
39 changes: 38 additions & 1 deletion scripts/effectManager/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SETTING_EFFECTS_MANAGER_STATE } from "../settings.js";
import { EffectManagerData } from "./models.js";
import { getMacroVariables, getSearchString } from "../utils.js";
import { CUSTOM_EFFECT_MODE_LID, CUSTOM_EFFECT_MODE_NAME, TOUR_ID } from "./consts.js";
import { weaponEffects } from "../weaponEffects.js";

/**
* Singleton app to manage effects.
Expand Down Expand Up @@ -131,6 +132,12 @@ export class EffectManagerApp extends FormApplication {

/* -------------------------------------------- */

/** @type {?Object<string, string>} */
_getDataCache_macro_choices;

/** @type {?Array<string>} */
_getDataCache_lids;

/** @override */
getData(options = {}) {
const dataModel = this._datamodel.toObject();
Expand All @@ -149,6 +156,34 @@ export class EffectManagerApp extends FormApplication {
effects: effects.filter(effect => effect.folderId === id),
}));

this._getDataCache_macro_choices ||= Object.fromEntries(
this.constructor._macroLookup.map(({ name, uuid }) => [uuid, name]),
);

this._getDataCache_lids ||= [
...Object.keys(weaponEffects),

"lwfx_cascade",
"lwfx_overcharge",
"lwfx_overheat",
"lwfx_overheat_emergency_shunt",
"lwfx_overheat_destabilized_power_plant",
"lwfx_overheat_meltdown_3",
"lwfx_overheat_meltdown_2",
"lwfx_overheat_meltdown_1",
"lwfx_overheat_irreversible_meltdown",
"lwfx_stabilize",
"lwfx_structure",
"lwfx_structure_glancing_blow",
"lwfx_structure_system_trauma",
"lwfx_structure_secondary",
"lwfx_structure_direct_hit_3",
"lwfx_structure_direct_hit_2",
"lwfx_structure_direct_hit_1",
"lwfx_structure_crushing_hit",
"lwfx_core_power",
].sort((a, b) => a.localeCompare(b, { sensitivity: "base" }));

return {
// TODO(v12) use fields to generate inputs
fields: this._datamodel.schema.fields,
Expand All @@ -172,8 +207,10 @@ export class EffectManagerApp extends FormApplication {
},

macros: {
choices: Object.fromEntries(this.constructor._macroLookup.map(({ name, uuid }) => [uuid, name])),
choices: this._getDataCache_macro_choices,
},

lids: this._getDataCache_lids,
};
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/effectResolver/effectResolver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { weaponEffects } from "./weaponEffects.js";
import { weaponEffects } from "../weaponEffects.js";
import { MODULE_ID, PACK_ID_WEAPONFX } from "../consts.js";
import { SETTING_EFFECTS_MANAGER_STATE } from "../settings.js";
import { getSearchString } from "../utils.js";
Expand Down
2 changes: 1 addition & 1 deletion scripts/flow/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export async function processFlowInfo(flowInfo) {
(temp_macro.flags[MODULE_ID] ||= {}).flowInfo = flowInfo;
temp_macro.ownership.default = CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER;

temp_macro.execute({ actor: sourceToken.actor, token: sourceToken });
temp_macro.execute({ actor: sourceToken?.actor, token: sourceToken });
}
File renamed without changes.
6 changes: 6 additions & 0 deletions templates/effectManager/effect-manager.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
class="standard-form lwfx-effects-manager lwfx__flexcol lwfx__h-100 lwfx__min-h-0"
data-drop-target="app"
>
<datalist id="lwfx-effects-manager-lids">
{{#each lids as |lid|}}
<option value="{{lid}}"></option>
{{/each}}
</datalist>

{{! Header controls }}
<div class="lwfx__flexcol lwfx__mb-1">
<div class="lwfx__flexrow-v-center lwfx__w-100 lwfx__min-w-0 lwfx__mb-1">
Expand Down
1 change: 1 addition & 0 deletions templates/effectManager/partial/effect-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
name="effects.{{effect.id}}.itemLid"
value="{{effect.itemLid}}"
class="lwfx-effects-manager__effect-ipt"
list="lwfx-effects-manager-lids"
>
</label>
{{/if}}
Expand Down

0 comments on commit 5eaa1eb

Please sign in to comment.