MAp management and helpers
This commit is contained in:
@@ -51,15 +51,36 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
},
|
||||
};
|
||||
this._tradeGoods = null;
|
||||
this._worldNames = {};
|
||||
|
||||
if (options.defaultWorld) {
|
||||
const w = options.defaultWorld;
|
||||
this._defaultWorld = w;
|
||||
this._worldNames['pax.uwpDep'] = w.name || '';
|
||||
this._worldNames['cargo.uwpDep'] = w.name || '';
|
||||
this._worldNames['trade.uwp'] = w.name || '';
|
||||
if (w.uwp) this._formData.pax.uwpDep = w.uwp;
|
||||
if (w.zone) this._formData.pax.zoneDep = w.zone;
|
||||
if (w.uwp) this._formData.cargo.uwpDep = w.uwp;
|
||||
if (w.zone) this._formData.cargo.zoneDep = w.zone;
|
||||
if (w.uwp) this._formData.trade.uwp = w.uwp;
|
||||
if (w.zone) this._formData.trade.zone = w.zone;
|
||||
this._activeTab = 'trade';
|
||||
}
|
||||
}
|
||||
|
||||
async _prepareContext() {
|
||||
_registerHandlebarsHelpers();
|
||||
return {
|
||||
const ctx = {
|
||||
...this._formData,
|
||||
activeActor: buildActiveActorContext(),
|
||||
activeTab: this._activeTab,
|
||||
};
|
||||
if (this._defaultWorld) {
|
||||
ctx.defaultWorldName = this._defaultWorld.name;
|
||||
ctx.defaultWorldLoc = `${this._defaultWorld.sector || ''} ${this._defaultWorld.hex || ''}`.trim();
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
async _onRender(context, options) {
|
||||
@@ -128,6 +149,12 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
|
||||
this._bindWorldSearch(html);
|
||||
|
||||
// Pré-remplir les champs recherche avec le nom du monde
|
||||
if (this._defaultWorld?.name) {
|
||||
html.find('.world-search-widget[data-role="dep"] .world-search-input, .world-block-full .world-search-input')
|
||||
.val(this._defaultWorld.name);
|
||||
}
|
||||
|
||||
html.on('click', (ev) => {
|
||||
if (!$(ev.target).closest('.world-search-widget').length) {
|
||||
html.find('.world-search-results').empty();
|
||||
@@ -204,6 +231,7 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
$li.on('click', async () => {
|
||||
$results.empty();
|
||||
$input.val(w.name);
|
||||
if (uwpTarget) this._worldNames[uwpTarget] = w.name;
|
||||
const [detail, coords] = await Promise.all([
|
||||
fetchWorldDetail(w.sector, w.hex).catch(() => null),
|
||||
fetchWorldCoordinates(w.sector, w.hex).catch(() => null),
|
||||
@@ -222,11 +250,13 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
html.find('[name="cargo.uwpDep"]').val(resolvedUwp);
|
||||
html.find('[name="cargo.zoneDep"]').val(resolvedZone);
|
||||
$cargoDep.data('coords', coords);
|
||||
this._worldNames['cargo.uwpDep'] = w.name;
|
||||
|
||||
const $tradeWorld = html.find('.world-search-widget[data-uwp-target="trade.uwp"]');
|
||||
$tradeWorld.find('.world-search-input').val(w.name);
|
||||
html.find('[name="trade.uwp"]').val(resolvedUwp);
|
||||
html.find('[name="trade.zone"]').val(resolvedZone);
|
||||
this._worldNames['trade.uwp'] = w.name;
|
||||
}
|
||||
|
||||
if (parsecsTarget) {
|
||||
@@ -370,6 +400,8 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
});
|
||||
|
||||
if (!result.success) return ui.notifications.error(result.errors.join(' | '));
|
||||
result.dep = { ...result.dep, name: this._worldNames['pax.uwpDep'] || '' };
|
||||
result.dest = { ...result.dest, name: this._worldNames['pax.uwpDest'] || '' };
|
||||
await this._postToChatResult(result);
|
||||
}
|
||||
|
||||
@@ -394,6 +426,8 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
|
||||
if (!result.success) return ui.notifications.error(result.errors.join(' | '));
|
||||
result.cargoRevenue = result.lots.reduce((s, l) => s + l.revenue, 0);
|
||||
result.dep = { ...result.dep, name: this._worldNames['cargo.uwpDep'] || '' };
|
||||
result.dest = { ...result.dest, name: this._worldNames['cargo.uwpDest'] || '' };
|
||||
await this._postToChatResult(result);
|
||||
}
|
||||
|
||||
@@ -413,6 +447,7 @@ export class CommerceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
|
||||
if (!result.success) return ui.notifications.error(result.errors.join(' | '));
|
||||
|
||||
result.world = { ...result.world, name: this._worldNames['trade.uwp'] || '' };
|
||||
this._tradeGoods = result;
|
||||
const goodsDiv = html.find('.trade-goods-result');
|
||||
const listDiv = html.find('.trade-goods-list');
|
||||
|
||||
Reference in New Issue
Block a user