fix ghost logic, add defaults and type conversion (#904)

This commit is contained in:
jberg 2019-09-06 08:06:31 -07:00 committed by Jordan Eldredge
parent 7c26257381
commit 803b89d9e0
2 changed files with 24 additions and 1 deletions

View file

@ -153,7 +153,7 @@ function GuiObjectEvents({ node, children }) {
}}
style={{
opacity: alpha == null ? 1 : alpha / 255,
pointerEvents: ghost === 1 ? "none" : null,
pointerEvents: ghost ? "none" : null,
}}
>
{children}
@ -329,6 +329,7 @@ function Button({
y,
downImage,
tooltip,
ghost,
node,
}) {
const [down, setDown] = React.useState(false);
@ -373,6 +374,7 @@ function Button({
width: Number(img.w),
height: Number(img.h),
backgroundImage: `url(${img.imgUrl})`,
pointerEvents: ghost ? "none" : null,
}}
>
<XmlChildren node={node} />

View file

@ -11,10 +11,31 @@ class GuiObject extends MakiObject {
constructor(node, parent, annotations, store) {
super(node, parent, annotations, store);
this._setAttributeDefaults(this.attributes);
this._convertAttributeTypes(this.attributes);
this.visible = true;
this._selectorCache = new Map();
}
_setAttributeDefaults(attributes) {
if (attributes.alpha == null) {
attributes.alpha = "255";
}
if (attributes.ghost == null) {
attributes.ghost = "0";
}
}
_convertAttributeTypes(attributes) {
if (attributes.alpha != null) {
attributes.alpha = Number(attributes.alpha);
}
if (attributes.ghost != null) {
attributes.ghost = !!Number(attributes.ghost);
}
}
_useUidSelector(selector) {
// TODO: use memoize for this
if (!this._selectorCache.has(selector)) {