Merge 2b12722daf
into fda87985c7
This commit is contained in:
commit
1e89926797
4 changed files with 36 additions and 15 deletions
|
@ -1,3 +1,3 @@
|
|||
The inital work on the HTML5 Scratch player was done by Tim Mickel. John Maloney provided feedback and guidance. Shane Clements took over the development and management late summer 2013.
|
||||
|
||||
Scimonster fixed some bugs and added some features: the time/date blocks, list reporter block, fixed timer blocks, added timer reporter.
|
||||
Scimonster fixed some bugs and added some features: the time/date blocks, list reporter block, fixed timer blocks, added timer reporter, added list watchers.
|
||||
|
|
|
@ -137,6 +137,7 @@ Reporter.prototype.changeSlider = function() {
|
|||
var List = function(data, sprite) {
|
||||
this.contents = data.contents;
|
||||
this.listName = data.listName;
|
||||
this.lastUpdated = null;
|
||||
|
||||
this.height = data.height;
|
||||
this.width = data.width;
|
||||
|
@ -205,6 +206,12 @@ List.prototype.update = function() {
|
|||
var s = this.scrollbar.height(c.height());
|
||||
s.children('.list-scrollbar').height(s.height()/c[0].scrollHeight*s.height()).css('display', s.children('.list-scrollbar').height()===c.height() ? 'none' : 'inline-block');
|
||||
this.el.find('.list-length').text('length: '+this.contents.length);
|
||||
if (this.lastUpdated !== null) {
|
||||
c.scrollTop(0); // so that the position().top is correct
|
||||
c.scrollTop(c.find('.list-index').eq(this.lastUpdated).css('color','yellow').position().top);
|
||||
s.children('.list-scrollbar').css('top',c.scrollTop()/(c.height()/s.children('.list-scrollbar').height()));
|
||||
this.lastUpdated = null;
|
||||
}
|
||||
};
|
||||
|
||||
List.prototype.updateLayer = function() {
|
||||
|
|
|
@ -106,6 +106,17 @@ function findList(targetSprite, listName) {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Take a list name and target sprite and return the List object associated with it
|
||||
function findListWatcher(targetSprite, listName) {
|
||||
var w = null;
|
||||
for (var r = 0; r < runtime.reporters.length; r++) {
|
||||
if (runtime.reporters[r] instanceof List && runtime.reporters[r].listName == listName && (runtime.reporters[r].target == targetSprite || runtime.reporters[r].target == 'Stage')) {
|
||||
w = runtime.reporters[r];
|
||||
}
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
VarListPrims.prototype.primReadList = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 0));
|
||||
if (list) {
|
||||
|
@ -117,6 +128,9 @@ VarListPrims.prototype.primReadList = function(b) {
|
|||
VarListPrims.prototype.primListAppend = function(b) {
|
||||
var list = findList(interp.targetSprite(), interp.arg(b, 1));
|
||||
if (list) list.push(interp.arg(b, 0));
|
||||
|
||||
var w = findListWatcher(interp.targetSprite().objName, interp.arg(b, 1));
|
||||
w.lastUpdated = list.length-1;
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListDeleteLine = function(b) {
|
||||
|
@ -148,6 +162,9 @@ VarListPrims.prototype.primListInsertAt = function(b) {
|
|||
if (position > list.length) return;
|
||||
|
||||
list.splice(position, 0, newItem);
|
||||
|
||||
var w = findListWatcher(interp.targetSprite().objName, interp.arg(b, 2));
|
||||
w.lastUpdated = position;
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListSetLine = function(b) {
|
||||
|
@ -166,6 +183,9 @@ VarListPrims.prototype.primListSetLine = function(b) {
|
|||
|
||||
if (position > list.length - 1) return;
|
||||
list[position] = newItem;
|
||||
|
||||
var w = findListWatcher(interp.targetSprite().objName, interp.arg(b, 1));
|
||||
w.lastUpdated = position;
|
||||
};
|
||||
|
||||
VarListPrims.prototype.primListLength = function(b) {
|
||||
|
@ -182,6 +202,9 @@ VarListPrims.prototype.primListGetLine = function(b) {
|
|||
if (line == 'random') line = Math.round(Math.random() * list.length);
|
||||
else if (line == 'last') line = list.length;
|
||||
else if (list.length < line) return 0;
|
||||
|
||||
var w = findListWatcher(interp.targetSprite().objName, interp.arg(b, 1));
|
||||
w.lastUpdated = line;
|
||||
return list[line - 1];
|
||||
};
|
||||
|
||||
|
@ -194,21 +217,11 @@ VarListPrims.prototype.primListContains = function(b) {
|
|||
};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
var w = findListWatcher(interp.targetSprite().objName, interp.arg(b, 0));
|
||||
w.visible = false;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
var w = findListWatcher(interp.targetSprite().objName, interp.arg(b, 0));
|
||||
w.visible = true;
|
||||
};
|
||||
|
|
|
@ -321,6 +321,7 @@ button#trigger-stop:hover {
|
|||
padding-left: 3px;
|
||||
font: bold 11px sans-serif;
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.list .list-title {
|
||||
|
|
Reference in a new issue