Add show/hide list blocks, fix list reporters, and fix show/hide var (issue was with multiple sprites having same local variable name).

This commit is contained in:
Scimonster 2013-11-04 22:28:23 +02:00
parent ba40cd3396
commit 01c35969d0
3 changed files with 70 additions and 22 deletions

View file

@ -91,22 +91,44 @@ IO.prototype.makeObjects = function() {
runtime.stage.attachPenLayer(runtime.scene);
runtime.stage.loadSounds();
// Create the sprites and watchers
$.each(this.data.children.concat(this.data.lists), function i(index, obj) {
function createObj(obj, sprite) {
var newSprite;
if(!obj.cmd && !obj.listName) { // sprite
newSprite = new Sprite(obj);
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 && !obj.listName)
function createSprite(obj) {
var newSprite = new Sprite(obj);
newSprite.loadSounds();
return newSprite;
}
function createReporter(obj, sprite) {
var newSprite;
if (obj.listName) { // list
if (!(sprite===runtime.stage && !runtime.stage.lists[obj.listName])) { // for local lists, only if in sprite
newSprite = new List(obj, sprite.objName);
runtime.reporters.push(newSprite);
}
} else {
newSprite = new Reporter(obj);
runtime.reporters.push(newSprite);
}
return newSprite;
}
if (obj.objName) { // sprite
newSprite = createSprite(obj);
sprite = newSprite;
} else {
newSprite = createReporter(obj, sprite);
}
if (newSprite) {
runtime.sprites.push(newSprite);
newSprite.attach(runtime.scene);
}
}
$.each(this.data.children, function(index, obj) {
createObj(obj, runtime.stage); // create children of stage - sprites, watchers, and stage's lists
});
$.each(runtime.sprites.filter(function(sprite){return sprite instanceof Sprite}), function(index, sprite) { // list of sprites
$.each(sprite.lists, function(index, list){
createObj(list, sprite); // create local lists
});
});
};

View file

@ -120,7 +120,7 @@ Reporter.prototype.changeSlider = function() {
target.variables[variable] = newValue;
};
var List = function(data) {
var List = function(data, sprite) {
this.contents = data.contents;
this.listName = data.listName;
@ -131,6 +131,8 @@ var List = function(data) {
this.z = io.getCount();
this.visible = data.visible;
this.target = sprite;
// this.isPersistent = data.isPersistent;
this.el = null; // jQuery element for list
@ -140,7 +142,7 @@ var List = function(data) {
List.prototype.attach = function(scene) {
this.el = $('<div class="list">');
this.el.append('<div class="list-title">'+this.listName);
this.el.append('<div class="list-title">'+(this.target==='Stage'?'':this.target+' ')+this.listName);
var c = this.containerEl = $('<div style="overflow:hidden;float:left;position:relative">').appendTo(this.el).width(this.width-19);
var s = this.scrollbar = $('<div class="list-scrollbar-container"><div class="list-scrollbar">').appendTo(this.el);
var sb = s.children('.list-scrollbar');
@ -175,6 +177,8 @@ List.prototype.attach = function(scene) {
};
List.prototype.update = function(){
this.contents = findList(runtime.spriteNamed(this.target),this.listName);
this.el.css('display', this.visible ? 'inline-block' : 'none');
if (!this.visible) return;

View file

@ -34,6 +34,8 @@ VarListPrims.prototype.addPrimsTo = function(primTable) {
primTable['lineCountOfList:'] = this.primListLength;
primTable['getLine:ofList:'] = this.primListGetLine;
primTable['list:contains:'] = this.primListContains;
primTable['hideList:'] = this.primHideList;
primTable['showList:'] = this.primShowList;
};
// Variable primitive implementations
@ -74,9 +76,9 @@ VarListPrims.prototype.primChangeVar = function(b) {
};
VarListPrims.prototype.primHideVar = function(b) {
var targetVar = interp.arg(b, 0);
var targetVar = interp.arg(b, 0), targetSprite = interp.targetSprite().objName;
for (var r = 0; r < runtime.reporters.length; r++) {
if (runtime.reporters[r].cmd == 'getVar:' && runtime.reporters[r].param == targetVar) {
if (runtime.reporters[r].cmd == 'getVar:' && runtime.reporters[r].param == targetVar && (runtime.reporters[r].target == targetSprite || runtime.reporters[r].target == 'Stage')) {
runtime.reporters[r].visible = false;
return;
}
@ -84,9 +86,9 @@ VarListPrims.prototype.primHideVar = function(b) {
};
VarListPrims.prototype.primShowVar = function(b) {
var targetVar = interp.arg(b, 0);
var targetVar = interp.arg(b, 0), targetSprite = interp.targetSprite().objName;
for (var r = 0; r < runtime.reporters.length; r++) {
if (runtime.reporters[r].cmd == 'getVar:' && runtime.reporters[r].param == targetVar) {
if (runtime.reporters[r].cmd == 'getVar:' && runtime.reporters[r].param == targetVar && (runtime.reporters[r].target == targetSprite || runtime.reporters[r].target == 'Stage')) {
runtime.reporters[r].visible = true;
return;
}
@ -96,7 +98,7 @@ VarListPrims.prototype.primShowVar = function(b) {
// List primitive implementations
// Take a list name and target sprite and return the JS list itself
var findList = function(targetSprite, listName) {
function findList(targetSprite, listName) {
if (targetSprite == null) targetSprite = runtime.stage;
if (listName in targetSprite.lists) {
return targetSprite.lists[listName].contents;
@ -104,7 +106,7 @@ var findList = function(targetSprite, listName) {
return runtime.stage.lists[listName].contents;
}
return null;
};
}
VarListPrims.prototype.primReadList = function(b) {
var list = findList(interp.targetSprite(), interp.arg(b, 0));
@ -181,3 +183,23 @@ VarListPrims.prototype.primListContains = function(b) {
if (parseFloat(searchItem) == searchItem) searchItem = parseFloat(searchItem);
return $.inArray(searchItem, list) > -1;
};
VarListPrims.prototype.primHideList = function(b) {
var targetList = interp.arg(b, 0), targetSprite = interp.targetSprite().objName;
for (var r = 0; r < runtime.reporters.length; r++) {
if (runtime.reporters[r] instanceof List && runtime.reporters[r].listName == targetList && (runtime.reporters[r].target == targetSprite || runtime.reporters[r].target == 'Stage')) {
runtime.reporters[r].visible = false;
return;
}
}
};
VarListPrims.prototype.primShowList = function(b) {
var targetList = interp.arg(b, 0), targetSprite = interp.targetSprite().objName;
for (var r = 0; r < runtime.reporters.length; r++) {
if (runtime.reporters[r] instanceof List && runtime.reporters[r].listName == targetList && (runtime.reporters[r].target == targetSprite || runtime.reporters[r].target == 'Stage')) {
runtime.reporters[r].visible = true;
return;
}
}
};