mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
.
This commit is contained in:
parent
eb954b7ef6
commit
db8c2e29c1
6 changed files with 93 additions and 12 deletions
|
|
@ -1,8 +1,15 @@
|
||||||
|
import { RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||||
|
|
||||||
export default class DhSceneConfigSettings extends foundry.applications.sheets.SceneConfig {
|
export default class DhSceneConfigSettings extends foundry.applications.sheets.SceneConfig {
|
||||||
constructor(options = {}) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
this.daggerheartFlag = new game.system.api.data.scenes.DHScene(this.document.flags.daggerheart);
|
Hooks.on(socketEvent.Refresh, ({ refreshType }) => {
|
||||||
|
if (refreshType === RefreshType.Scene) {
|
||||||
|
this.daggerheartFlag = new game.system.api.data.scenes.DHScene(this.document.flags.daggerheart);
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEFAULT_OPTIONS = {
|
static DEFAULT_OPTIONS = {
|
||||||
|
|
@ -33,6 +40,11 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S
|
||||||
|
|
||||||
static TABS = DhSceneConfigSettings.buildTabs();
|
static TABS = DhSceneConfigSettings.buildTabs();
|
||||||
|
|
||||||
|
async _preFirstRender(context, options) {
|
||||||
|
await super._preFirstRender(context, options);
|
||||||
|
this.daggerheartFlag = new game.system.api.data.scenes.DHScene(this.document.flags.daggerheart);
|
||||||
|
}
|
||||||
|
|
||||||
_attachPartListeners(partId, htmlElement, options) {
|
_attachPartListeners(partId, htmlElement, options) {
|
||||||
super._attachPartListeners(partId, htmlElement, options);
|
super._attachPartListeners(partId, htmlElement, options);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,13 @@ export default class DhSceneNavigation extends foundry.applications.ui.SceneNavi
|
||||||
if (!scene.flags.daggerheart) return x;
|
if (!scene.flags.daggerheart) return x;
|
||||||
|
|
||||||
const daggerheartInfo = new game.system.api.data.scenes.DHScene(scene.flags.daggerheart);
|
const daggerheartInfo = new game.system.api.data.scenes.DHScene(scene.flags.daggerheart);
|
||||||
const environmentKeys = Object.keys(daggerheartInfo.sceneEnvironments);
|
const environments = daggerheartInfo.sceneEnvironments.filter(x => x);
|
||||||
const hasEnvironments = environmentKeys.length;
|
const hasEnvironments = environments.length > 0;
|
||||||
return {
|
return {
|
||||||
...x,
|
...x,
|
||||||
hasEnvironments,
|
hasEnvironments,
|
||||||
environmentImage: hasEnvironments
|
environmentImage: hasEnvironments ? environments[0].img : null,
|
||||||
? daggerheartInfo.sceneEnvironments[environmentKeys[0]].img
|
environments: environments
|
||||||
: null,
|
|
||||||
environments: daggerheartInfo.sceneEnvironments
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
context.scenes.active = extendScenes(context.scenes.active);
|
context.scenes.active = extendScenes(context.scenes.active);
|
||||||
|
|
@ -47,7 +45,7 @@ export default class DhSceneNavigation extends foundry.applications.ui.SceneNavi
|
||||||
const scene = game.scenes.get(button.dataset.sceneId);
|
const scene = game.scenes.get(button.dataset.sceneId);
|
||||||
const sceneEnvironments = new game.system.api.data.scenes.DHScene(scene.flags.daggerheart).sceneEnvironments;
|
const sceneEnvironments = new game.system.api.data.scenes.DHScene(scene.flags.daggerheart).sceneEnvironments;
|
||||||
|
|
||||||
if (sceneEnvironments.length === 1) {
|
if (sceneEnvironments.length === 1 || event.shiftKey) {
|
||||||
sceneEnvironments[0].sheet.render(true);
|
sceneEnvironments[0].sheet.render(true);
|
||||||
} else {
|
} else {
|
||||||
new ContextMenu(
|
new ContextMenu(
|
||||||
|
|
@ -56,6 +54,15 @@ export default class DhSceneNavigation extends foundry.applications.ui.SceneNavi
|
||||||
sceneEnvironments.map(environment => ({
|
sceneEnvironments.map(environment => ({
|
||||||
name: environment.name,
|
name: environment.name,
|
||||||
callback: () => {
|
callback: () => {
|
||||||
|
if (scene.flags.daggerheart.sceneEnvironments[0] !== environment.uuid) {
|
||||||
|
const newEnvironments = scene.flags.daggerheart.sceneEnvironments;
|
||||||
|
const newFirst = newEnvironments.splice(
|
||||||
|
newEnvironments.findIndex(x => x === environment.uuid)
|
||||||
|
)[0];
|
||||||
|
newEnvironments.unshift(newFirst);
|
||||||
|
scene.update({ 'flags.daggerheart.sceneEnvironments': newEnvironments });
|
||||||
|
}
|
||||||
|
|
||||||
environment.sheet.render({ force: true });
|
environment.sheet.render({ force: true });
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
import BaseDataActor from './base.mjs';
|
import BaseDataActor from './base.mjs';
|
||||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||||
import DHEnvironmentSettings from '../../applications/sheets-configs/environment-settings.mjs';
|
import DHEnvironmentSettings from '../../applications/sheets-configs/environment-settings.mjs';
|
||||||
|
import { RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||||
|
|
||||||
export default class DhEnvironment extends BaseDataActor {
|
export default class DhEnvironment extends BaseDataActor {
|
||||||
|
scenes = new Set();
|
||||||
|
|
||||||
/**@override */
|
/**@override */
|
||||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Environment'];
|
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Environment'];
|
||||||
|
|
||||||
|
|
@ -53,6 +56,31 @@ export default class DhEnvironment extends BaseDataActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
isItemValid(source) {
|
isItemValid(source) {
|
||||||
return source.type === "feature";
|
return source.type === 'feature';
|
||||||
|
}
|
||||||
|
|
||||||
|
_onUpdate(changes, options, userId) {
|
||||||
|
super._onUpdate(changes, options, userId);
|
||||||
|
for (const scene of this.scenes) {
|
||||||
|
scene.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onDelete(options, userId) {
|
||||||
|
super._onDelete(options, userId);
|
||||||
|
for (const scene of this.scenes) {
|
||||||
|
if (game.user.isActiveGM) {
|
||||||
|
const newSceneEnvironments = scene.flags.daggerheart.sceneEnvironments.filter(
|
||||||
|
x => x !== this.parent.uuid
|
||||||
|
);
|
||||||
|
scene.update({ 'flags.daggerheart.sceneEnvironments': newSceneEnvironments }).then(() => {
|
||||||
|
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Scene });
|
||||||
|
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||||
|
action: socketEvent.Refresh,
|
||||||
|
data: { refreshType: RefreshType.TagTeamRoll }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||||
|
|
||||||
|
/* Foundry does not add any system data for subtyped Scenes. The data model is therefore mainly for reference until this changes.
|
||||||
|
Needed dataprep and lifetime hooks are handled in documents/scene.
|
||||||
|
*/
|
||||||
export default class DHScene extends foundry.abstract.DataModel {
|
export default class DHScene extends foundry.abstract.DataModel {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
|
|
@ -16,7 +19,7 @@ export default class DHScene extends foundry.abstract.DataModel {
|
||||||
close: new fields.NumberField({ integer: true, label: 'DAGGERHEART.CONFIG.Range.close.name' }),
|
close: new fields.NumberField({ integer: true, label: 'DAGGERHEART.CONFIG.Range.close.name' }),
|
||||||
far: new fields.NumberField({ integer: true, label: 'DAGGERHEART.CONFIG.Range.far.name' })
|
far: new fields.NumberField({ integer: true, label: 'DAGGERHEART.CONFIG.Range.far.name' })
|
||||||
}),
|
}),
|
||||||
sceneEnvironments: new ForeignDocumentUUIDArrayField({ type: 'Actor' })
|
sceneEnvironments: new ForeignDocumentUUIDArrayField({ type: 'Actor', prune: true })
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,30 @@ export default class DhScene extends Scene {
|
||||||
this.#sizeSyncBatch.clear();
|
this.#sizeSyncBatch.clear();
|
||||||
this.updateEmbeddedDocuments('Token', entries, { animation: { movementSpeed: 1.5 } });
|
this.updateEmbeddedDocuments('Token', entries, { animation: { movementSpeed: 1.5 } });
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
prepareBaseData() {
|
||||||
|
super.prepareBaseData();
|
||||||
|
|
||||||
|
if (this instanceof game.system.api.documents.DhScene) {
|
||||||
|
const system = new game.system.api.data.scenes.DHScene(this.flags.daggerheart);
|
||||||
|
|
||||||
|
// Register this scene to all environements
|
||||||
|
for (const environment of system.sceneEnvironments) {
|
||||||
|
environment.system.scenes?.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onDelete(options, userId) {
|
||||||
|
super._onDelete(options, userId);
|
||||||
|
|
||||||
|
if (this instanceof game.system.api.documents.DhScene) {
|
||||||
|
const system = new game.system.api.data.scenes.DHScene(this.flags.daggerheart);
|
||||||
|
|
||||||
|
// Clear this scene from all environments that aren't deleted
|
||||||
|
for (const environement of system.sceneEnvironments) {
|
||||||
|
environement?.system?.scenes?.delete(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@ export const GMUpdateEvent = {
|
||||||
export const RefreshType = {
|
export const RefreshType = {
|
||||||
Countdown: 'DhCoundownRefresh',
|
Countdown: 'DhCoundownRefresh',
|
||||||
TagTeamRoll: 'DhTagTeamRollRefresh',
|
TagTeamRoll: 'DhTagTeamRollRefresh',
|
||||||
EffectsDisplay: 'DhEffectsDisplayRefresh'
|
EffectsDisplay: 'DhEffectsDisplayRefresh',
|
||||||
|
Scene: 'DhSceneRefresh'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerSocketHooks = () => {
|
export const registerSocketHooks = () => {
|
||||||
|
|
@ -92,6 +93,10 @@ export const registerSocketHooks = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Hooks.on(socketEvent.RefreshDocument, async data => {
|
||||||
|
const document = await foundry.utils.fromUuid(data.uuid);
|
||||||
|
document.sheet.render();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerUserQueries = () => {
|
export const registerUserQueries = () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue