Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: views #130

Draft
wants to merge 5 commits into
base: development
Choose a base branch
from
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
1 change: 1 addition & 0 deletions js/5etools-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const betteR205etools = function () {
d20plus.ut.fix3dDice();
d20plus.engine.addLayers();
d20plus.weather.addWeather();
d20plus.views.addViews();
d20plus.engine.repairPrototypeMethods();
d20plus.engine.disableFrameRecorder();
// d20plus.ut.fixSidebarLayout();
Expand Down
70 changes: 70 additions & 0 deletions js/base-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,20 @@ function d20plusEngine () {
d20plus.anim.animatorTool.doStartScene(sceneUid);
});
i();
} else if (["assignview0", "assignview1", "assignview2", "assignview3"].includes(e)) {
const viewId = e.at(-1);
d20.engine.selected().forEach(it => {
if (it.model) {
if (it.model.get(`bR20_view${viewId}`)) {
it.model.set(`bR20_view${viewId}`, false);
} else {
it.model.set(`bR20_view${viewId}`, true);
}
it.saveState();
it.model.save();
}
});
i();
}
// END MOD
return !1
Expand Down Expand Up @@ -1254,6 +1268,62 @@ function d20plusEngine () {
})
};

d20plus.engine.objectsStashProps = (obj, state) => {
const props = [
"emits_bright_light",
"emits_low_light",
"has_directional_bright_light",
"has_directional_dim_light",
"showplayers_bar1",
"showplayers_bar2",
"showplayers_bar3",
"showname",
];
props.each((prop) => {
if (!state) {
if (obj.attributes[prop]) {
obj.attributes[`bR20_${prop}`] = true;
obj.attributes[prop] = false;
}
} else {
if (obj.attributes[`bR20_${prop}`]) {
obj.attributes[prop] = true;
obj.attributes[`bR20_${prop}`] = false;
delete obj.attributes[`bR20_${prop}`];
}
}
});
}

d20plus.engine.objectsHideUnhide = (query, val, prefix, state) => {
let some = false;
for (const o of d20.engine.canvas._objects) {
const model = o.model;
if (!model) continue;
if (`${model.get(query)}`.search(val) > -1) {
const l = model.attributes.layer;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer e.g. const {layer} = model.attributes to randomly one-letter-renaming vars

if (state) {
if (l.search(prefix) > -1) {
model.attributes.layer = l.replace(`${prefix}_`, "");
d20plus.engine.objectsStashProps(model, true);
o.saveState();
model.save();
some = true;
}
} else {
if (l.search(prefix) === -1) {
model.attributes.layer = `${prefix}_${l}`;
d20plus.engine.objectsStashProps(model, false);
o.saveState();
model.save();
some = true;
}
}
}
}
return some;
};

d20plus.engine.addLayers = () => {
d20plus.ut.log("Adding layers");

Expand Down
22 changes: 22 additions & 0 deletions js/base-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ const baseTemplate = function () {
</li>
<$ } $>

<!-- BEGIN MOD -->
<$ if(this.view && this.get && d20.Campaign.activePage().get && d20.Campaign.activePage().get('bR20cfg_viewsEnable')) { $>
<li class='head hasSub' data-menuname='view'>
Assign view &raquo;
<ul class='submenu' data-menuname='view'>
<$ if(this.view && d20.Campaign.activePage().get('bR20cfg_viewsEnable')) { $>
<li data-action-type="assignview0" class='<$ if(this && this.get && this && this.get("bR20_view0")) { $>active<$ } $>'><span class="pictos ctx__layer-icon">P</span><$ if (d20.Campaign.activePage().get('bR20cfg_views0Name')) { $> <$!d20.Campaign.activePage().get('bR20cfg_views0Name')$> <$ } else { $> View 1 <$ } $></li>
<$ } $>
<$ if(this.view && d20.Campaign.activePage().get('bR20cfg_views1Enable')) { $>
<li data-action-type="assignview1" class='<$ if(this && this.get && this && this.get("bR20_view1")) { $>active<$ } $>'><span class="pictos ctx__layer-icon">P</span><$ if (d20.Campaign.activePage().get('bR20cfg_views1Name')) { $> <$!d20.Campaign.activePage().get('bR20cfg_views1Name')$> <$ } else { $> View 2 <$ } $></li>
<$ } $>
<$ if(this.view && d20.Campaign.activePage().get('bR20cfg_views2Enable')) { $>
<li data-action-type="assignview2" class='<$ if(this && this.get && this && this.get("bR20_view2")) { $>active<$ } $>'><span class="pictos ctx__layer-icon">P</span><$ if (d20.Campaign.activePage().get('bR20cfg_views2Name')) { $> <$!d20.Campaign.activePage().get('bR20cfg_views2Name')$> <$ } else { $> View 3 <$ } $></li>
<$ } $>
<$ if(this.view && d20.Campaign.activePage().get('bR20cfg_views3Enable')) { $>
<li data-action-type="assignview3" class='<$ if(this && this.get && this && this.get("bR20_view3")) { $>active<$ } $>'><span class="pictos ctx__layer-icon">P</span><$ if (d20.Campaign.activePage().get('bR20cfg_views3Name')) { $> <$!d20.Campaign.activePage().get('bR20cfg_views3Name')$> <$ } else { $> View 4 <$ } $></li>
<$ } $>
</ul>
</li>
<$ } $>
<!-- END MOD -->

<$ if(this.view && this.get && this.get("sides") !== "" && this.get("cardid") === "") { $>
<li class='head hasSub' data-menuname='mutliside'>
Multi-Sided &raquo;
Expand Down
8 changes: 8 additions & 0 deletions js/base-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,14 @@ function baseUtil () {
}
};

d20plus.ut.dynamicStyles = (slug) => {
if (!d20plus.css.dynamic) d20plus.css.dynamic = {};
if (!d20plus.css.dynamic[slug]) {
d20plus.css.dynamic[slug] = $("<style></style>").appendTo("body");
}
return d20plus.css.dynamic[slug];
}

/**
* Assumes any other lists have been searched using the same term
*/
Expand Down
Loading