initial player stuff

This commit is contained in:
Blue 2018-08-05 00:52:16 +03:00 committed by Gitea
parent 4b60ece582
commit 00f26c431e
38 changed files with 1107 additions and 93 deletions

View file

@ -0,0 +1,69 @@
"use strict";
var Controller = require("./controller");
var String = require("./string");
var Vocabulary = require("../wType/vocabulary");
var Button = Controller.inherit({
"className": "Button",
"constructor": function(addr) {
Controller.fn.constructor.call(this, addr);
this.enabled = false;
this.hasLabel = false;
this.addHandler("get");
this.addHandler("setLabel");
this.addHandler("setImage");
this.addHandler("setEnabled");
this.addHandler("changeImage");
},
"destructor": function() {
Controller.fn.destructor.call(this);
},
"activate": function() {
if (this.enabled) {
this.send(new Vocabulary, "activate");
}
},
"_h_changeImage": function(ev) {
},
"_h_get": function(ev) {
this._h_setLabel(ev);
this._h_setImage(ev);
this._h_setEnabled(ev);
},
"_h_setEnabled": function(ev) {
var data = ev.getData();
var enabled = data.at("enabled").valueOf();
if (this.enabled !== enabled) {
this.enabled = enabled;
this.trigger("setEnabled", this.enabled);
}
},
"_h_setLabel": function(ev) {
var data = ev.getData();
var hasLabel = data.at("hasLabel").valueOf();
if (hasLabel !== this.hasLabel) {
this.hasLabel = hasLabel;
if (hasLabel) {
this.label = new String(data.at("label").clone());
this.addController(this.label);
this.trigger("setLabel", true, this.label);
} else {
this.trigger("setLabel", false);
this.removeController(this.label);
this.label.destructor();
}
}
},
"_h_setImage": function(ev) {
}
});
module.exports = Button;

View file

@ -328,8 +328,10 @@ Controller.ModelType = {
String: 0,
List: 1,
Vocabulary: 2,
Image: 3,
Controller: 4,
Catalogue: 3,
Image: 4,
Button: 5,
Controller: 6,
Attributes: 50,
@ -339,15 +341,18 @@ Controller.ModelType = {
PageStorage: 103,
PanesList: 104,
Theme: 105,
ThemeStorage: 106
ThemeStorage: 106,
Player: 107
};
Controller.ReversedModelType = {
"0": "String",
"1": "List",
"2": "Vocabulary",
"3": "Image",
"4": "Controller",
"3": "Catalogue",
"4": "Image",
"5": "Button",
"6": "Controller",
"50": "Attributes",
@ -357,7 +362,8 @@ Controller.ReversedModelType = {
"103": "PageStorage",
"104": "PanesList",
"105": "Theme",
"106": "ThemeStorage"
"106": "ThemeStorage",
"107": "Player"
};
Controller.ModelTypesPaths = {
@ -372,7 +378,10 @@ Controller.ModelTypesPaths = {
PanesList: "./panesList", //resolve as dependency
Theme: "./theme", //resolve as dependency
ThemeStorage: "./themeStorage", //resolve as dependency
Image: "./image" //resolve as dependency
Image: "./image", //resolve as dependency
Button: "./button", //resolve as dependency
Catalogue: "./catalogue", //resolve as dependency
Player: "./player" //resolve as dependency
};
Controller.constructors = {

View file

@ -10,16 +10,12 @@ var Link = Controller.inherit({
"constructor": function(addr) {
Controller.fn.constructor.call(this, addr);
var hop = new Address(["label"]);
this.targetAddress = new Address([]);
this.label = new String(addr['+'](hop));
this.addController(this.label);
this.addHandler("get");
hop.destructor();
},
"destructor": function() {
this.targetAddress.destructor();
@ -35,4 +31,6 @@ var Link = Controller.inherit({
}
});
var hop = new Address(["label"]);
module.exports = Link;

View file

@ -13,5 +13,6 @@ configure_file(themeStorage.js themeStorage.js)
configure_file(vocabulary.js vocabulary.js)
configure_file(attributes.js attributes.js)
configure_file(image.js image.js)
configure_file(button.js button.js)
add_subdirectory(proxy)

90
libjs/wModel/button.js Normal file
View file

@ -0,0 +1,90 @@
"use strict";
var Model = require("./model");
var ModelString = require("./string");
var Vocabulary = require("../wType/vocabulary");
var Boolean = require("../wType/boolean");
var Address = require("../wType/address");
var String = require("../wType/string");
var Button = Model.inherit({
"className": "Button",
"constructor": function(address) {
Model.fn.constructor.call(this, address);
this._enabled = true;
this._hasImage = false;
this._hasLabel =false;
this._imageName = undefined;
this._label = undefined;
this.addHandler("get");
this.addHandler("activate");
},
"setImage": function(name) {
if (this._hasImage) {
if (this._imageName !== name) {
this._image = name;
var vc = new Vocabulary();
vc.insert("image", new String(this._imageName));
this.broadcast(vc, "changeImage");
}
} else {
this._image = name;
this._hasImage = true;
var vc = new Vocabulary();
vc.insert("image", new String(this._imageName));
this.broadcast(vc, "setImage");
}
},
"setEnabled": function(enabled) {
if (enabled !== this._enabled) {
this._enabled = enabled;
var vc = new Vocabulary();
vc.insert("enabled", new Boolean(this._enabled));
this.broadcast(vc, "setEnabled");
}
},
"setLabel": function(text) {
if (this._hasLabel) {
this._label.set(text);
} else {
this._label = new ModelString(this._address["+"](labelHop), text);
this.addModel(this._label);
var vc = new Vocabulary();
vc.insert("hasLabel", new Boolean(true));
vc.insert("label", this._label.getAddress());
this.broadcast(vc, "setLabel");
this._hasLabel = true;
}
},
"_h_subscribe": function(ev) {
Model.fn._h_subscribe.call(this, ev);
this._h_get(ev);
},
"_h_get": function(ev) {
var vc = new Vocabulary();
vc.insert("hasImage", new Boolean(this._hasImage));
if (this._hasImage) {
vc.insert("image", new String(this._imageName));
}
vc.insert("hasLabel", new Boolean(this._hasLabel));
if (this._hasLabel) {
vc.insert("label", this._label.getAddress());
}
vc.insert("enabled", new Boolean(this._enabled));
this.response(vc, "get", ev);
},
"_h_activate": function() {
if (this._enabled) {
this.trigger("activated");
}
}
});
var labelHop = new Address(["label"]);
module.exports = Button;

View file

@ -299,8 +299,10 @@ Model.ModelType = {
String: 0,
List: 1,
Vocabulary: 2,
Image: 3,
Model: 4,
//Catalogue: 3,
Image: 4,
Button: 5,
Model: 6,
Attributes: 50,
@ -310,7 +312,8 @@ Model.ModelType = {
PageStorage: 103,
PanesList: 104,
Theme: 105,
ThemeStorage: 106
ThemeStorage: 106,
Player: 107
};
module.exports = Model;