Fix the instanceof operators on the proxy to include the default class
This commit is contained in:
parent
23ec5fe0d3
commit
59b64f57db
2 changed files with 17 additions and 11 deletions
|
|
@ -5,12 +5,14 @@ const classes = {
|
|||
aspect: Aspect,
|
||||
};
|
||||
|
||||
const defaultClass = DotDungeonItem;
|
||||
|
||||
export const ItemProxy = new Proxy(function () {}, {
|
||||
construct(target, args) {
|
||||
const [data] = args;
|
||||
|
||||
if (!classes.hasOwnProperty(data.type)) {
|
||||
return new DotDungeonItem(...args);
|
||||
return new defaultClass(...args);
|
||||
}
|
||||
|
||||
return new classes[data.type](...args);
|
||||
|
|
@ -24,19 +26,20 @@ export const ItemProxy = new Proxy(function () {}, {
|
|||
}
|
||||
|
||||
if (!classes.hasOwnProperty(data.type)) {
|
||||
return DotDungeonItem.create(data, options);
|
||||
return defaultClass.create(data, options);
|
||||
}
|
||||
|
||||
return classes[data.type].create(data, options)
|
||||
return classes[data.type].create(data, options);
|
||||
};
|
||||
};
|
||||
|
||||
if (prop == Symbol.hasInstance) {
|
||||
return function (instance) {
|
||||
return Object.values(classes).some(i => instance instanceof i)
|
||||
if (instance instanceof defaultClass) return true;
|
||||
return Object.values(classes).some(i => instance instanceof i);
|
||||
};
|
||||
};
|
||||
|
||||
return DotDungeonItem[prop];
|
||||
return defaultClass[prop];
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue