Skip to content

Commit

Permalink
Merge branch 'develop' into issue/remove-function
Browse files Browse the repository at this point in the history
# Conflicts:
#	dist/entry.js
#	dist/entry.min.js
#	src/entry.js
#	src/variable_container.js
#	src/workspace/thread.js
  • Loading branch information
SeonMyungLim committed Aug 19, 2016
2 parents 738b6f4 + c631aec commit 7432f8f
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 243 deletions.
44 changes: 32 additions & 12 deletions dist/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Entry = {block:{}, TEXT_ALIGN_CENTER:0, TEXT_ALIGN_LEFT:1, TEXT_ALIGN_RIGHT:2, TEXT_ALIGNS:["center", "left", "right"], clipboard:null, loadProject:function(b) {
b || (b = Entry.getStartProject(Entry.mediaFilePath));
this.setFuncRefs(b.functions);
"workspace" == this.type && Entry.stateManager.startIgnore();
Entry.projectId = b._id;
Entry.variableContainer.setVariables(b.variables);
Expand Down Expand Up @@ -123,6 +124,12 @@ var Entry = {block:{}, TEXT_ALIGN_CENTER:0, TEXT_ALIGN_LEFT:1, TEXT_ALIGN_RIGHT:
a.template = Lang.template.function_general;
Entry.block[b] = a;
}
}, setFuncRefs:function(b) {
this.functions = b ? b.map(function(a) {
return a.id;
}) : [];
}, removeFuncRefs:function() {
delete this.functions;
}};
window.Entry = Entry;
Entry.Albert = {PORT_MAP:{leftWheel:0, rightWheel:0, buzzer:0, leftEye:0, rightEye:0, note:0, bodyLed:0, frontLed:0, padWidth:0, padHeight:0}, setZero:function() {
Expand Down Expand Up @@ -8087,17 +8094,30 @@ Entry.EntryObject = function(b) {
this.clonedEntities = [];
Entry.stage.loadObject(this);
for (c in this.pictures) {
var d = this.pictures[c];
d.objectId = this.id;
d.id || (d.id = Entry.generateHash());
var e = new Image;
d.fileurl ? e.src = d.fileurl : d.fileurl ? e.src = d.fileurl : (b = d.filename, e.src = Entry.defaultPath + "/uploads/" + b.substring(0, 2) + "/" + b.substring(2, 4) + "/image/" + b + ".png");
Entry.Loader.addQueue();
e.onload = function(b) {
Entry.container.cachePicture(d.id + a.entity.id, e);
Entry.Loader.removeQueue();
Entry.requestUpdate = !0;
};
(function(b) {
b.objectId = this.id;
b.id || (b.id = Entry.generateHash());
var c = new Image;
if (b.fileurl) {
c.src = b.fileurl;
} else {
if (b.fileurl) {
c.src = b.fileurl;
} else {
var f = b.filename;
c.src = Entry.defaultPath + "/uploads/" + f.substring(0, 2) + "/" + f.substring(2, 4) + "/image/" + f + ".png";
}
}
Entry.Loader.addQueue();
c.onload = function(c) {
Entry.container.cachePicture(b.id + a.entity.id, this);
Entry.requestUpdate = !0;
Entry.Loader.removeQueue();
};
c.onerror = function(a) {
Entry.Loader.removeQueue();
};
})(this.pictures[c]);
}
}
};
Expand Down Expand Up @@ -11961,7 +11981,7 @@ Entry.setCloneBrush = function(b, a) {
b.shape = d;
};
Entry.isFloat = function(b) {
return /\d+\.{1}\d+/.test(b);
return /\d+\.{1}\d+$/.test(b);
};
Entry.getStringIndex = function(b) {
if (!b) {
Expand Down
313 changes: 156 additions & 157 deletions dist/entry.min.js

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Entry.loadProject = function(project) {
project = Entry.getStartProject(Entry.mediaFilePath);
}

this.setFuncRefs(project.functions);

if (this.type == 'workspace')
Entry.stateManager.startIgnore();
Entry.projectId = project._id;
Expand All @@ -49,7 +51,6 @@ Entry.loadProject = function(project) {
if (Object.keys(Entry.container.inputValue).length === 0)
Entry.variableContainer.generateAnswer();
Entry.start();

return project;
};

Expand Down Expand Up @@ -354,4 +355,18 @@ Entry.generateFunctionSchema = function(functionId) {
Entry.block[functionId] = blockSchema;
};

Entry.setFuncRefs = function(functions) {
if (!functions) this.functions = [];
else {
this.functions = functions.map(function(f) {
return f.id;
});
}
};

Entry.removeFuncRefs = function() {
delete this.functions;
};


window.Entry = Entry;
42 changes: 23 additions & 19 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,33 @@ Entry.EntryObject = function(model) {
Entry.stage.loadObject(this);

for (var i in this.pictures) {
var picture = this.pictures[i];
picture.objectId = this.id;
if (!picture.id)
picture.id = Entry.generateHash();
var image = new Image();
if (picture.fileurl) {
image.src = picture.fileurl;
} else {
(function (picture) {
picture.objectId = this.id;
if (!picture.id)
picture.id = Entry.generateHash();
var image = new Image();
if (picture.fileurl) {
image.src = picture.fileurl;
} else {
var fileName = picture.filename;
image.src = Entry.defaultPath + '/uploads/' + fileName.substring(0, 2) + '/' +
fileName.substring(2, 4) + '/image/' + fileName + '.png';
if (picture.fileurl) {
image.src = picture.fileurl;
} else {
var fileName = picture.filename;
image.src = Entry.defaultPath + '/uploads/' + fileName.substring(0, 2) + '/' +
fileName.substring(2, 4) + '/image/' + fileName + '.png';
}
}
}
Entry.Loader.addQueue();
image.onload = function(e) {
Entry.container.cachePicture(
picture.id + that.entity.id, image);
Entry.Loader.removeQueue();
Entry.requestUpdate = true;
};
Entry.Loader.addQueue();
image.onload = function(e) {
Entry.container.cachePicture(
picture.id + that.entity.id, this);
Entry.requestUpdate = true;
Entry.Loader.removeQueue();
};
image.onerror = function(err) {
Entry.Loader.removeQueue();
}
})(this.pictures[i]);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ Entry.setCloneBrush = function (sprite, parentBrush) {
};

Entry.isFloat = function (num) {
return /\d+\.{1}\d+/.test(num);
return /\d+\.{1}\d+$/.test(num);
};

Entry.getStringIndex = function(str) {
Expand Down
81 changes: 30 additions & 51 deletions src/workspace/block_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1937,18 +1937,11 @@ Entry.block = {
var port = script.getField("PORT", script);
var nowTime = Entry.ArduinoExt.getSensorTime(Entry.ArduinoExt.sensorTypes.ANALOG);
var hardwareTime = Entry.hw.portData['TIME'] || 0;
if(!Entry.ArduinoExt.BlockState[this.type]) {
Entry.ArduinoExt.BlockState[this.type] = {
isStart: false,
stamp: 0
}
}

var state = Entry.ArduinoExt.BlockState[this.type];
var scope = script.executor.scope;
var ANALOG = Entry.hw.portData.ANALOG;
if(!state.isStart) {
state.isStart = true;
state.stamp = nowTime;
if(!scope.isStart) {
scope.isStart = true;
scope.stamp = nowTime;
Entry.hw.sendQueue['TIME'] = nowTime;
Entry.hw.sendQueue['KEY'] = Entry.ArduinoExt.getSensorKey();
Entry.hw.sendQueue['GET'] = {
Expand All @@ -1957,13 +1950,13 @@ Entry.block = {
};
throw new Entry.Utils.AsyncError();
return;
} else if(hardwareTime && (hardwareTime === state.stamp)) {
delete state.isStart;
delete state.stamp;
} else if(hardwareTime && (hardwareTime === scope.stamp)) {
delete scope.isStart;
delete scope.stamp;
return (ANALOG) ? ANALOG[port] || 0 : 0;
} else if(nowTime - state.stamp > 64) {
delete state.isStart;
delete state.stamp;
} else if(nowTime - scope.stamp > 64) {
delete scope.isStart;
delete scope.stamp;
return (ANALOG) ? ANALOG[port] || 0 : 0;
} else {
throw new Entry.Utils.AsyncError();
Expand Down Expand Up @@ -2034,19 +2027,12 @@ Entry.block = {
"func": function (sprite, script) {
var port1 = script.getField("PORT1", script);
var port2 = script.getField("PORT2", script);
if(!Entry.ArduinoExt.BlockState[this.type]) {
Entry.ArduinoExt.BlockState[this.type] = {
isStart: false,
stamp: 0
}
}

var state = Entry.ArduinoExt.BlockState[this.type];
var scope = script.executor.scope;
var nowTime = Entry.ArduinoExt.getSensorTime(Entry.ArduinoExt.sensorTypes.ULTRASONIC);
var hardwareTime = Entry.hw.portData['TIME'] || 0;
if(!state.isStart) {
state.isStart = true;
state.stamp = nowTime;
if(!scope.isStart) {
scope.isStart = true;
scope.stamp = nowTime;
Entry.hw.sendQueue['TIME'] = nowTime;
Entry.hw.sendQueue['KEY'] = Entry.ArduinoExt.getSensorKey();
Entry.hw.sendQueue['GET'] = {
Expand All @@ -2055,13 +2041,13 @@ Entry.block = {
};
throw new Entry.Utils.AsyncError();
return;
} else if(hardwareTime && (hardwareTime === state.stamp)) {
delete state.isStart;
delete state.stamp;
} else if(hardwareTime && (hardwareTime === scope.stamp)) {
delete scope.isStart;
delete scope.stamp;
return Entry.hw.portData.ULTRASONIC || 0;
} else if(nowTime - state.stamp > 64) {
delete state.isStart;
delete state.stamp;
} else if(nowTime - scope.stamp > 64) {
delete scope.isStart;
delete scope.stamp;
return Entry.hw.portData.ULTRASONIC || 0;
} else {
throw new Entry.Utils.AsyncError();
Expand Down Expand Up @@ -2388,18 +2374,11 @@ Entry.block = {
var port = script.getNumberValue("PORT", script);
var nowTime = Entry.ArduinoExt.getSensorTime(Entry.ArduinoExt.sensorTypes.DIGITAL);
var hardwareTime = Entry.hw.portData['TIME'] || 0;
if(!Entry.ArduinoExt.BlockState[this.type]) {
Entry.ArduinoExt.BlockState[this.type] = {
isStart: false,
stamp: 0
}
}

var state = Entry.ArduinoExt.BlockState[this.type];
var scope = script.executor.scope;
var DIGITAL = Entry.hw.portData.DIGITAL;
if(!state.isStart) {
state.isStart = true;
state.stamp = nowTime;
if(!scope.isStart) {
scope.isStart = true;
scope.stamp = nowTime;
Entry.hw.sendQueue['TIME'] = nowTime;
Entry.hw.sendQueue['KEY'] = Entry.ArduinoExt.getSensorKey();
Entry.hw.sendQueue['GET'] = {
Expand All @@ -2408,13 +2387,13 @@ Entry.block = {
};
throw new Entry.Utils.AsyncError();
return;
} else if(hardwareTime && (hardwareTime === state.stamp)) {
delete state.isStart;
delete state.stamp;
} else if(hardwareTime && (hardwareTime === scope.stamp)) {
delete scope.isStart;
delete scope.stamp;
return (DIGITAL) ? DIGITAL[port] || 0 : 0;
} else if(nowTime - state.stamp > 64) {
delete state.isStart;
delete state.stamp;
} else if(nowTime - scope.stamp > 64) {
delete scope.isStart;
delete scope.stamp;
return (DIGITAL) ? DIGITAL[port] || 0 : 0;
} else {
throw new Entry.Utils.AsyncError();
Expand Down
3 changes: 1 addition & 2 deletions src/workspace/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Entry.Thread = function(thread, code, parent) {
if (block instanceof Entry.Block || block.isDummy) {
block.setThread(this);
this._data.push(block);
} else
this._data.push(new Entry.Block(block, this));
} else this._data.push(new Entry.Block(block, this));
}

var codeView = this._code.view;
Expand Down

0 comments on commit 7432f8f

Please sign in to comment.