Start work on List class. I'm not quite sure what i'm doing here, but it seems to work.
This commit is contained in:
parent
45b86691ed
commit
8934e1e577
3 changed files with 125 additions and 5 deletions
14
js/IO.js
14
js/IO.js
|
@ -93,18 +93,22 @@ IO.prototype.makeObjects = function() {
|
|||
runtime.stage.attachPenLayer(runtime.scene);
|
||||
runtime.stage.loadSounds();
|
||||
|
||||
// Create the sprites
|
||||
$.each(this.data.children, function(index, obj) {
|
||||
// Create the sprites and watchers
|
||||
$.each(this.data.children.concat(this.data.lists), function i(index, obj) {
|
||||
var newSprite;
|
||||
if(!obj.cmd) {
|
||||
if(!obj.cmd && !obj.listName) { // sprite
|
||||
newSprite = new Sprite(obj);
|
||||
} else {
|
||||
if (obj.lists) $.each(obj.lists, i);
|
||||
} else if (!obj.listName) { // watcher
|
||||
newSprite = new Reporter(obj);
|
||||
runtime.reporters.push(newSprite);
|
||||
} else { // list
|
||||
newSprite = new List(obj);
|
||||
runtime.reporters.push(newSprite);
|
||||
}
|
||||
runtime.sprites.push(newSprite);
|
||||
newSprite.attach(runtime.scene);
|
||||
if (!obj.cmd)
|
||||
if (!obj.cmd && !obj.listName)
|
||||
newSprite.loadSounds();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -118,3 +118,51 @@ Reporter.prototype.changeSlider = function() {
|
|||
var variable = $(this).attr('data-var');
|
||||
target.variables[variable] = newValue;
|
||||
}
|
||||
|
||||
var List = function(data) {
|
||||
this.contents = data.contents;
|
||||
this.listName = data.listName;
|
||||
|
||||
this.height = data.height;
|
||||
this.width = data.width;
|
||||
this.x = data.x;
|
||||
this.y = data.y;
|
||||
this.z = io.getCount();
|
||||
this.visible = data.visible;
|
||||
|
||||
// this.isPersistent = data.isPersistent;
|
||||
|
||||
this.el = null; // jQuery element for list
|
||||
this.containerEl = null;
|
||||
};
|
||||
|
||||
List.prototype.attach = function(scene) {
|
||||
this.el = $('<div class="list">');
|
||||
this.el.append('<div class="list-title">'+this.listName);
|
||||
this.containerEl = $('<div style="width:99%">').appendTo(this.el);
|
||||
this.el.append('<div class="list-add">+');
|
||||
this.el.append('<div class="list-length">length: '+this.contents.length);
|
||||
scene.append(this.el);
|
||||
this.update();
|
||||
this.el.css('left', this.x);
|
||||
this.el.css('top', this.y);
|
||||
this.el.width(this.width);
|
||||
this.el.height(this.height);
|
||||
this.el.css('z-index', this.z);
|
||||
this.el.css('display', this.visible ? 'inline-block' : 'none');
|
||||
}
|
||||
|
||||
List.prototype.update = function(){
|
||||
this.el.css('display', this.visible ? 'inline-block' : 'none');
|
||||
if (!this.visible) return;
|
||||
|
||||
var c = this.containerEl.html(''); // so that it can be used inside the forEach
|
||||
this.contents.forEach(function(val,i){
|
||||
$('<div style="clear:both">').appendTo(c).append('<div class="list-index">'+(i+1),'<div class="list-item">'+val);
|
||||
});
|
||||
this.el.find('.list-length').text('length: '+this.contents.length);
|
||||
};
|
||||
|
||||
List.prototype.updateLayer = function() {
|
||||
this.el.css('z-index', this.z);
|
||||
}
|
||||
|
|
Reference in a new issue