mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-24 10:37:16 +00:00
Remove the Redux store from Maki objects
This commit is contained in:
parent
bd4b938268
commit
1f3cb76212
7 changed files with 40 additions and 106 deletions
|
|
@ -1,44 +0,0 @@
|
|||
import * as Utils from "./utils";
|
||||
import { ModernAppState, XmlNode } from "./types";
|
||||
|
||||
function findNodeByUid(uid: number) {
|
||||
// TODO: Do some clever caching here.
|
||||
return (state: ModernAppState): XmlNode => {
|
||||
return Utils.findInTree(
|
||||
state.modernSkin.xmlTree,
|
||||
(node: XmlNode): boolean => {
|
||||
return node.uid === uid;
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function getTop(uid: number) {
|
||||
const findNodeInState = findNodeByUid(uid);
|
||||
return (state: ModernAppState): number => {
|
||||
const node = findNodeInState(state);
|
||||
return Number(node.attributes.y) || 0;
|
||||
};
|
||||
}
|
||||
|
||||
export function getPathToUid(uid: number) {
|
||||
return (state: ModernAppState): number[] | null => {
|
||||
return Utils.findPathToNode(
|
||||
state.modernSkin.xmlTree,
|
||||
node => node.uid === uid
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function getNodeAtPath(path: number[]) {
|
||||
return (state: ModernAppState): XmlNode | null => {
|
||||
let node = state.modernSkin.xmlTree;
|
||||
path.forEach(offset => {
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
node = node.children[offset];
|
||||
});
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
|
@ -61,12 +61,10 @@ function imageAttributesFromNode(node) {
|
|||
}
|
||||
}
|
||||
|
||||
const noop = (node, parent, zip, store) =>
|
||||
new GuiObject(node, parent, undefined, store);
|
||||
const noop = (node, parent, zip) => new GuiObject(node, parent, undefined);
|
||||
|
||||
const parsers = {
|
||||
groupdef: (node, parent, zip, store) =>
|
||||
new JsGroupDef(node, parent, undefined, store),
|
||||
groupdef: (node, parent, zip) => new JsGroupDef(node, parent, undefined),
|
||||
skininfo: noop,
|
||||
guiobject: noop,
|
||||
version: noop,
|
||||
|
|
@ -77,49 +75,38 @@ const parsers = {
|
|||
email: noop,
|
||||
homepage: noop,
|
||||
screenshot: noop,
|
||||
container: (node, parent, zip, store) =>
|
||||
new Container(node, parent, undefined, store),
|
||||
container: (node, parent, zip) => new Container(node, parent, undefined),
|
||||
scripts: noop,
|
||||
gammaset: (node, parent, zip, store) =>
|
||||
new JsGammaSet(node, parent, undefined, store),
|
||||
gammaset: (node, parent, zip) => new JsGammaSet(node, parent, undefined),
|
||||
color: noop,
|
||||
layer: (node, parent, zip, store) =>
|
||||
new Layer(node, parent, undefined, store),
|
||||
layer: (node, parent, zip) => new Layer(node, parent, undefined),
|
||||
layoutstatus: noop,
|
||||
hideobject: noop,
|
||||
button: (node, parent, zip, store) =>
|
||||
new Button(node, parent, undefined, store),
|
||||
group: (node, parent, zip, store) =>
|
||||
new Group(node, parent, undefined, store),
|
||||
layout: (node, parent, zip, store) =>
|
||||
new Layout(node, parent, undefined, store),
|
||||
button: (node, parent, zip) => new Button(node, parent, undefined),
|
||||
group: (node, parent, zip) => new Group(node, parent, undefined),
|
||||
layout: (node, parent, zip) => new Layout(node, parent, undefined),
|
||||
sendparams: noop,
|
||||
elements: (node, parent, zip, store) =>
|
||||
new JsElements(node, parent, undefined, store),
|
||||
elements: (node, parent, zip) => new JsElements(node, parent, undefined),
|
||||
bitmap: noop,
|
||||
eqvis: (node, parent, zip, store) =>
|
||||
new EqVis(node, parent, undefined, store),
|
||||
slider: (node, parent, zip, store) =>
|
||||
new Slider(node, parent, undefined, store),
|
||||
eqvis: (node, parent, zip) => new EqVis(node, parent, undefined),
|
||||
slider: (node, parent, zip) => new Slider(node, parent, undefined),
|
||||
gammagroup: noop,
|
||||
truetypefont: async (node, parent, zip, store) => {
|
||||
truetypefont: async (node, parent, zip) => {
|
||||
const { file } = node.attributes;
|
||||
const font = Utils.getCaseInsensitveFile(zip, file);
|
||||
const fontBlob = await font.async("blob");
|
||||
const fontUrl = await Utils.getUrlFromBlob(fontBlob);
|
||||
const fontFamily = `font-${Utils.getId()}-${file.replace(/\./, "_")}`;
|
||||
await Utils.loadFont(fontUrl, fontFamily);
|
||||
return new MakiObject(node, parent, { fontFamily }, store);
|
||||
return new MakiObject(node, parent, { fontFamily });
|
||||
},
|
||||
component: (node, parent, zip, store) =>
|
||||
new Component(node, parent, undefined, store),
|
||||
text: (node, parent, zip, store) => new Text(node, parent, undefined, store),
|
||||
togglebutton: (node, parent, zip, store) =>
|
||||
new ToggleButton(node, parent, undefined, store),
|
||||
status: (node, parent, zip, store) =>
|
||||
new Status(node, parent, undefined, store),
|
||||
component: (node, parent, zip) => new Component(node, parent, undefined),
|
||||
text: (node, parent, zip) => new Text(node, parent, undefined),
|
||||
togglebutton: (node, parent, zip) =>
|
||||
new ToggleButton(node, parent, undefined),
|
||||
status: (node, parent, zip) => new Status(node, parent, undefined),
|
||||
bitmapfont: noop,
|
||||
vis: (node, parent, zip, store) => new Vis(node, parent, undefined, store),
|
||||
vis: (node, parent, zip) => new Vis(node, parent, undefined),
|
||||
"wasabi:titlebar": noop,
|
||||
"colorthemes:list": noop,
|
||||
"wasabi:standardframe:status": noop,
|
||||
|
|
@ -131,8 +118,8 @@ const parsers = {
|
|||
elementalias: noop,
|
||||
grid: noop,
|
||||
rect: noop,
|
||||
animatedlayer: (node, parent, zip, store) =>
|
||||
new AnimatedLayer(node, parent, undefined, store),
|
||||
animatedlayer: (node, parent, zip) =>
|
||||
new AnimatedLayer(node, parent, undefined),
|
||||
nstatesbutton: noop,
|
||||
songticker: noop,
|
||||
menu: noop,
|
||||
|
|
@ -141,7 +128,7 @@ const parsers = {
|
|||
script: noop,
|
||||
};
|
||||
|
||||
async function parseChildren(node, children, zip, store) {
|
||||
async function parseChildren(node, children, zip) {
|
||||
if (node.type === "comment") {
|
||||
return;
|
||||
}
|
||||
|
|
@ -157,7 +144,7 @@ async function parseChildren(node, children, zip, store) {
|
|||
}
|
||||
if (child.type === "text") {
|
||||
// TODO: Handle text
|
||||
return new MakiObject({ ...child }, node, undefined, store);
|
||||
return new MakiObject({ ...child }, node, undefined);
|
||||
}
|
||||
if (child.name == null) {
|
||||
console.error(child);
|
||||
|
|
@ -174,10 +161,10 @@ async function parseChildren(node, children, zip, store) {
|
|||
console.warn(`Missing parser in initialize for ${childName}`);
|
||||
childParser = noop;
|
||||
}
|
||||
const parsedChild = await childParser(child, node, zip, store);
|
||||
const parsedChild = await childParser(child, node, zip);
|
||||
child.maki = parsedChild;
|
||||
if (child.children != null && child.children.length > 0) {
|
||||
await parseChildren(parsedChild, child.children, zip, store);
|
||||
await parseChildren(parsedChild, child.children, zip);
|
||||
}
|
||||
return parsedChild;
|
||||
})
|
||||
|
|
@ -265,11 +252,11 @@ async function applyGroupDefs(root) {
|
|||
});
|
||||
}
|
||||
|
||||
async function initialize(zip, skinXml, store) {
|
||||
async function initialize(zip, skinXml) {
|
||||
const xmlRoot = skinXml.children[0];
|
||||
await applyImageLookups(xmlRoot, zip);
|
||||
const root = new JsWinampAbstractionLayer(xmlRoot, null, undefined, store);
|
||||
await parseChildren(root, xmlRoot.children, zip, store);
|
||||
const root = new JsWinampAbstractionLayer(xmlRoot, null, undefined);
|
||||
await parseChildren(root, xmlRoot.children, zip);
|
||||
await applyGroupDefs(root);
|
||||
return root;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ class AnimatedLayer extends Layer {
|
|||
_frameNum: number;
|
||||
_animationStartTime: number;
|
||||
|
||||
constructor(node, parent, annotations, store) {
|
||||
super(node, parent, annotations, store);
|
||||
constructor(node, parent, annotations) {
|
||||
super(node, parent, annotations);
|
||||
|
||||
this._setAttributeDefaults();
|
||||
this._convertAttributeTypes();
|
||||
|
|
|
|||
|
|
@ -33,13 +33,8 @@ class GuiObject extends MakiObject {
|
|||
_transitionParams: TransitionParams;
|
||||
_targetAnimationStartTime: number;
|
||||
_targetAnimationCancelID: number | null;
|
||||
constructor(
|
||||
node: XmlNode,
|
||||
parent: MakiObject,
|
||||
annotations: Object = {},
|
||||
store: ModernStore
|
||||
) {
|
||||
super(node, parent, annotations, store);
|
||||
constructor(node: XmlNode, parent: MakiObject, annotations: Object = {}) {
|
||||
super(node, parent, annotations);
|
||||
|
||||
this._setAttributeDefaults();
|
||||
this._convertAttributeTypes();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import Emitter from "../Emitter";
|
||||
import * as Utils from "../utils";
|
||||
import { ModernStore, XmlNode } from "../types";
|
||||
import { XmlNode } from "../types";
|
||||
|
||||
class MakiObject {
|
||||
_node: XmlNode;
|
||||
name: string;
|
||||
_uid: number;
|
||||
_store: ModernStore;
|
||||
// TODO: This should really just be `string | undefined` and we should handle
|
||||
// type conversion differently. Having one type that holds both the pre and
|
||||
// post type coerced values is too confusing.
|
||||
|
|
@ -16,14 +15,8 @@ class MakiObject {
|
|||
children: MakiObject[];
|
||||
js_annotations: Object;
|
||||
|
||||
constructor(
|
||||
node: XmlNode,
|
||||
parent: MakiObject,
|
||||
annotations: Object = {},
|
||||
store: ModernStore
|
||||
) {
|
||||
constructor(node: XmlNode, parent: MakiObject, annotations: Object = {}) {
|
||||
this._node = node;
|
||||
this._store = store;
|
||||
if (node) {
|
||||
this._uid = node.uid;
|
||||
this.attributes = node.attributes || {};
|
||||
|
|
|
|||
|
|
@ -7,14 +7,17 @@ import {
|
|||
} from "../utils";
|
||||
import * as Actions from "../Actions";
|
||||
import * as Selectors from "../Selectors";
|
||||
import { ModernStore } from "../types";
|
||||
|
||||
class System extends MakiObject {
|
||||
scriptGroup: Group;
|
||||
root: MakiObject;
|
||||
_store: ModernStore;
|
||||
_privateInt: Map<string, Map<string, number>>;
|
||||
_privateString: Map<string, Map<string, string>>;
|
||||
constructor(scriptGroup, store) {
|
||||
super(null, null, {}, store);
|
||||
super(null, null, {});
|
||||
this._store = store;
|
||||
|
||||
this.scriptGroup = scriptGroup == null ? new Group() : scriptGroup;
|
||||
this.root = scriptGroup;
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ class Timer extends MakiObject {
|
|||
_animationStartTime: number;
|
||||
_animationCancelID: number;
|
||||
|
||||
constructor(node, parent, annotations, store) {
|
||||
super(node, parent, annotations, store);
|
||||
constructor(node, parent, annotations) {
|
||||
super(node, parent, annotations);
|
||||
|
||||
this._speed = 200;
|
||||
this._animationStartTime = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue