Use getclassname to avoid dependency cyle

This commit is contained in:
Jordan Eldredge 2019-08-05 08:04:00 -07:00
parent 8a2aef62f4
commit 656c4ef8a9
19 changed files with 53 additions and 47 deletions

View file

@ -7,7 +7,7 @@ class Button extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassname() {
return "Button";
}
}

View file

@ -8,7 +8,7 @@ class Container extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Container";
}
getlayout(id) {

View file

@ -7,7 +7,7 @@ class Group extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Group";
}
getobject(id) {

View file

@ -13,7 +13,7 @@ class GuiObject extends MakiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "GuiObject";
}
findobject(id) {
@ -52,17 +52,17 @@ class GuiObject extends MakiObject {
}
gettop() {
unimplementedWarning('gettop');
unimplementedWarning("gettop");
return 5;
}
getheight() {
unimplementedWarning('getheight');
unimplementedWarning("getheight");
return 100;
}
getwidth() {
unimplementedWarning('getwidth');
unimplementedWarning("getwidth");
return 100;
}

View file

@ -7,7 +7,7 @@ class JsElements extends MakiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassname() {
return "Elements";
}
}

View file

@ -7,7 +7,7 @@ class JsGammaSet extends MakiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "GammaSet";
}
}

View file

@ -7,7 +7,7 @@ class JsGroupDef extends MakiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassname() {
return "GroupDef";
}
}

View file

@ -7,7 +7,7 @@ class Layer extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Layer";
}
}

View file

@ -8,11 +8,11 @@ class Layout extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Layout";
}
getcontainer() {
return findParentNodeOfType(this, ["container"]);;
return findParentNodeOfType(this, ["container"]);
}
resize(x, y, w, h) {

View file

@ -7,7 +7,7 @@ class List extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "List";
}
}

View file

@ -19,8 +19,8 @@ class MakiObject {
},
// ugly but works for now
name: this.constructor.name.toLowerCase(),
type: 'element'
}
type: "element",
};
}
}
@ -68,7 +68,7 @@ class MakiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Object";
}

View file

@ -8,20 +8,20 @@ class PopupMenu extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "PopupMenu";
}
addcommand(txt, id, checked, disabled) {
unimplementedWarning('addcommand');
unimplementedWarning("addcommand");
}
addseparator() {
unimplementedWarning('addseparator');
unimplementedWarning("addseparator");
}
checkcommand(id, check) {
unimplementedWarning('checkcommand');
unimplementedWarning("checkcommand");
}
popatmouse() {
unimplementedWarning('popatmouse');
unimplementedWarning("popatmouse");
}
}

View file

@ -7,7 +7,7 @@ class Slider extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getClassName() {
getclassaname() {
return "Slider";
}
}

View file

@ -7,7 +7,7 @@ class Status extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Status";
}
}

View file

@ -8,7 +8,7 @@ class System extends MakiObject {
this.scriptGroup = scriptGroup;
this.root = scriptGroup;
while(this.root.parent) {
while (this.root.parent) {
this.root = this.root.parent;
}
}
@ -19,7 +19,7 @@ class System extends MakiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "System";
}
@ -37,11 +37,11 @@ class System extends MakiObject {
return "5.666";
}
gettoken(str, separator, tokennum) {
unimplementedWarning('gettoken');
unimplementedWarning("gettoken");
return "Some Token String";
}
getparam() {
unimplementedWarning('getparam');
unimplementedWarning("getparam");
return "Some String";
}
messagebox(message, msgtitle, flag, notanymoreId) {
@ -51,22 +51,22 @@ class System extends MakiObject {
return value.toString();
}
getprivateint(section, item, defvalue) {
unimplementedWarning('getprivateint');
unimplementedWarning("getprivateint");
return defvalue;
}
setprivateint(section, item, defvalue) {
unimplementedWarning('setprivateint');
unimplementedWarning("setprivateint");
}
getleftvumeter() {
unimplementedWarning('getleftvumeter');
unimplementedWarning("getleftvumeter");
return 0.5;
}
getrightvumeter() {
unimplementedWarning('getrightvumeter');
unimplementedWarning("getrightvumeter");
return 0.5;
}
getvolume() {
unimplementedWarning('getvolume');
unimplementedWarning("getvolume");
return 1;
}
}

View file

@ -7,7 +7,7 @@ class Text extends GuiObject {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "Text";
}
}

View file

@ -7,7 +7,7 @@ class ToggleButton extends Button {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "ToggleButton";
}
}

View file

@ -8,7 +8,7 @@ class WinampAbstractionLayer extends Group {
* Returns the class name for the object.
* @ret The class name.
*/
static getclassname() {
getclassaname() {
return "WinampAbstractionLayer";
}
}

View file

@ -1,6 +1,4 @@
import { xml2js } from "xml-js";
const JsElements = require("./runtime/JsElements");
const JsGroupDef = require("./runtime/JsGroupDef");
export function getCaseInsensitveFile(zip, filename) {
// TODO: Escape `file` for rejex characters
@ -108,8 +106,10 @@ export function findParentNodeOfType(node, type) {
let n = node;
while (n.parent) {
n = n.parent;
if ((!Array.isArray(type) && n.xmlNode.name === type) ||
(Array.isArray(type) && type.includes(n.xmlNode.name))) {
if (
(!Array.isArray(type) && n.xmlNode.name === type) ||
(Array.isArray(type) && type.includes(n.xmlNode.name))
) {
return n;
}
}
@ -121,12 +121,14 @@ export function findDescendantByTypeAndId(node, type, id) {
}
const idLC = id.toLowerCase();
for(let i = 0; i < node.children.length; i++) {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i];
if ((!type || child.xmlNode.name === type) &&
(child.xmlNode.attributes !== undefined &&
child.xmlNode.attributes.id !== undefined &&
child.xmlNode.attributes.id.toLowerCase() === idLC)) {
if (
(!type || child.xmlNode.name === type) &&
(child.xmlNode.attributes !== undefined &&
child.xmlNode.attributes.id !== undefined &&
child.xmlNode.attributes.id.toLowerCase() === idLC)
) {
return child;
}
}
@ -173,7 +175,7 @@ function findInLexicalScope(node, pred) {
// return the first child of an <Elements> that matches id
export function findElementById(node, id) {
return findInLexicalScope(node, child => {
if (child instanceof JsElements) {
if (child.getclassname && child.getclassname() === "Elements") {
const element = findDirectDescendantById(child, id);
if (element) {
return element;
@ -185,7 +187,11 @@ export function findElementById(node, id) {
// Search up the tree for a <GroupDef> node that is in node's lexical scope and matches id.
export function findGroupDefById(node, id) {
return findInLexicalScope(node, child => {
if (child instanceof JsGroupDef && child.xmlNode.attributes.id === id) {
if (
child.getclassname &&
child.getclassname() === "GroupDef" &&
child.xmlNode.attributes.id === id
) {
return child;
}
});