Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Mar 24, 2017
1 parent b8fa3e9 commit d092fb5
Show file tree
Hide file tree
Showing 27 changed files with 299 additions and 1,799 deletions.
8 changes: 4 additions & 4 deletions behaviors/rex_bHash/edittime.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,27 @@ AddAction(22, 0, "Sort", "Array",
AddStringParam("Key string", "The key string of the hash table value to set.", '""');
AddStringParam("JSON", "JSON string.", '"{}"');
AddAction(23, 0, "Push JSON", "Array - Push",
"Push JSON <i>{1}</i> into array at <i>{0}</i> ",
"Push JSON <i>{1}</i> into array <i>{0}</i> ",
"Push JSON into array.", "PushJSON");

AddStringParam("Key string", "The key string of the hash table value to set.", '""');
AddAnyTypeParam("Value", "The value to push in the hash table.", 0);
AddAction(24, 0, "Push value", "Array - Push",
"Push value <i>{1}</i> into array at <i>{0}</i> ",
"Push value <i>{1}</i> into array <i>{0}</i> ",
"Push value into array.", "PushValue");

AddStringParam("Key string", "The key string of the hash table value to set.", '""');
AddStringParam("JSON", "JSON string.", '"{}"');
AddNumberParam("Index", "Index of this array to insert.", 0);
AddAction(25, 0, "Insert JSON", "Array - Insert",
"Insert JSON <i>{1}</i> into array at <i>{0}</i>[<i>{2}</i>]",
"Insert JSON <i>{1}</i> at array <i>{0}</i>[<i>{2}</i>]",
"Insert JSON into array.", "InsertJSON");

AddStringParam("Key string", "The key string of the hash table value to set.", '""');
AddAnyTypeParam("Value", "The value to push in the hash table.", 0);
AddNumberParam("Index", "Index of this array to insert.", 0);
AddAction(26, 0, "Insert value", "Array - Insert",
"Insert value <i>{1}</i> into array at <i>{0}</i>[<i>{2}</i>]",
"Insert value <i>{1}</i> at array <i>{0}</i>[<i>{2}</i>]",
"Insert value into array.", "InsertValue");

AddAnyTypeParam("Value", "The value to push in the hash table.", 0);
Expand Down
34 changes: 18 additions & 16 deletions behaviors/rex_bHash/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cr.behaviors.Rex_bHash = function(runtime)
this.currentEntry = this.hashtable;
};

behinstProto.getEntry = function(keys, root)
behinstProto.getEntry = function(keys, root, defaultEntry)
{
var entry = root || this.hashtable;
if ((keys === "") || (keys.length === 0))
Expand All @@ -84,11 +84,23 @@ cr.behaviors.Rex_bHash = function(runtime)
var i, cnt=keys.length, key;
for (i=0; i< cnt; i++)
{
key = keys[i];
key = keys[i];
if ( (entry[key] == null) || (typeof(entry[key]) !== "object") )
entry[key] = {};
{
var newEntry;
if (i === cnt-1)
{
newEntry = defaultEntry || {};
}
else
{
newEntry = {};
}

entry[key] = newEntry;
}

entry = entry[key];
entry = entry[key];
}
}

Expand Down Expand Up @@ -609,12 +621,7 @@ cr.behaviors.Rex_bHash = function(runtime)

Acts.prototype.PushValue = function (keys, val)
{
var arr = this.getEntry(keys);
if (arr == null)
{
this.setValue(keys, []);
arr = this.getEntry(keys);
}
var arr = this.getEntry(keys, null, []);
if (!isArray(arr))
return;

Expand All @@ -629,12 +636,7 @@ cr.behaviors.Rex_bHash = function(runtime)

Acts.prototype.InsertValue = function (keys, val, idx)
{
var arr = this.getEntry(keys);
if (arr == null)
{
this.setValue(keys, []);
arr = this.getEntry(keys);
}
var arr = this.getEntry(keys, null, []);
if (!isArray(arr))
return;

Expand Down
7 changes: 4 additions & 3 deletions behaviors/rex_shakeMod/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ cr.behaviors.Rex_ShakeMod = function(runtime)
return;

var dt = this.runtime.getDt(this.inst);
if (dt === 0)
if (dt == 0)
return;

// save origin to current position
Expand All @@ -101,6 +101,8 @@ cr.behaviors.Rex_ShakeMod = function(runtime)

if (isEnded)
{
this.OX = null;
this.OY = null;
this.isShaking = false;
this.is_my_call = true;
this.runtime.trigger(cr.behaviors.Rex_ShakeMod.prototype.cnds.OnShackingEnd, this.inst);
Expand Down Expand Up @@ -132,7 +134,7 @@ cr.behaviors.Rex_ShakeMod = function(runtime)

// add offset to origin
var nx = this.OX + offx;
var ny = this.OY + offy;
var ny = this.OY + offy;
if ((nx !== this.inst.x) || (ny !== this.inst.y))
{
this.inst.x = nx;
Expand All @@ -158,7 +160,6 @@ cr.behaviors.Rex_ShakeMod = function(runtime)
// go back to origin point
this.inst.x = this.OX;
this.inst.y = this.OY;

this.OX = null;
this.OY = null;

Expand Down
87 changes: 69 additions & 18 deletions behaviors/rex_spline/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,17 @@ cr.behaviors.Rex_Spline = function(runtime)
{
if (dt == null)
dt = this.runtime.getDt(this.inst);
if (dt === 0)
if ((dt === 0) || (this.speed == 0))
return;

var remainDist = this.speed*dt;
var sRemDist = remainDist/3;
var tickMovingDist = this.speed*dt;
var tMD2 = tickMovingDist*tickMovingDist;
var sTickMovingDist=tickMovingDist/20;
var segDist=null, t;
var x0=this.inst.x, y0=this.inst.y;
var seg, nx, ny, dist;
while (remainDist > 0)
var seg, nx, ny, dist, dist2, i=0;
var preX, preY, preDist2, preSegT;
while (1)
{
seg = this.getSeg();
if (seg == null)
Expand All @@ -104,12 +106,13 @@ cr.behaviors.Rex_Spline = function(runtime)
if (segDist !== seg.dist)
{
segDist = seg.dist
t = sRemDist/segDist;
if (t > 0.34)
t = 0.34; // 3 points at least
t = (sTickMovingDist/segDist);
if (t > 0.5)
t = 0.5; // 2 points at least
}

seg.t += t;
i++;
if (seg.t >= 1)
{
seg.t = 1;
Expand All @@ -121,14 +124,41 @@ cr.behaviors.Rex_Spline = function(runtime)
nx=interpolate(seg, 0, this.tension);
ny=interpolate(seg, 1, this.tension);
}

dist = cr.distanceTo(seg.preX, seg.preY, nx, ny);
this.traveledDist += dist;
remainDist -= dist;

this.inst.x = nx;
this.inst.y = ny;
}

dist2 = distance2(x0, y0, nx, ny);
if (dist2 >= tMD2)
{
if (Math.abs(preDist2 - tMD2) < Math.abs(dist2 - tMD2))
{
nx = preX;
ny = preY;
dist2 = preDist2;
seg.t = preSegT;
}

dist = Math.sqrt(dist2);
this.traveledDist += dist;
this.inst.x = nx;
this.inst.y = ny;

// debug
//var diff = Math.abs(dist-tickMovingDist)/tickMovingDist;
//diff = Math.floor(diff*100)/100;
//if (diff < 1)
// console.log(tickMovingDist + "," + dist+ " :" + diff + "; " + i);
//else
// console.warn(tickMovingDist + "," + dist+ " :" + diff + "; " + i);

break;
}
else
{
preX = nx;
preY = ny;
preDist2 = dist2;
preSegT = (seg.t === 1)? 0:seg.t;
}
} // while(1)

if ((x0 === this.inst.x) && (y0 === this.inst.y))
this.movingAngle = this.inst.angle;
Expand All @@ -154,6 +184,13 @@ cr.behaviors.Rex_Spline = function(runtime)
}
};

var distance2 = function(x0, y0, x1, y1)
{
var dx = (x1-x0);
var dy = (y1-y0);
return dx*dx + dy*dy;
}

behinstProto.start = function ()
{
this.curSeg.ptr = -1;
Expand Down Expand Up @@ -321,8 +358,22 @@ cr.behaviors.Rex_Spline = function(runtime)
this.traveledDist = o["td"];
this.movingAngle = o["ma"];
this.is_moving = o["mov"];
};

};

/**BEGIN-PREVIEWONLY**/
behinstProto.getDebuggerValues = function (propsections)
{
var idx0 = this.curSeg.ptr;
var idx1 = this.wrapIndex(this.curSeg.ptr + 1)
var p0 = this.points[idx0];
var p1 = this.points[idx1];
propsections.push({
"title": this.type.name,
"properties": [{"name": "P"+idx0, "value": p0[0] + "," + p0[1]},
{"name": "P"+idx1, "value": p1[0] + "," + p1[1]}]
});
};
/**END-PREVIEWONLY**/
//////////////////////////////////////
// Conditions
function Cnds() {};
Expand Down
51 changes: 23 additions & 28 deletions behaviors/rex_text_properties/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,6 @@ cr.behaviors.Rex_text_properties = function(runtime)
this._get_webgl_ctx():this.runtime.ctx;
inst.draw(ctx); // call this function to get lines
};

behinstProto.lineBreakContent = function ()
{
this.drawText();
var content;
if ((this.text_type === "Text") || (this.text_type === "Spritefont2"))
{
content = this.inst.lines.join("\n");
}
else if ((this.text_type === "rex_TagText") || (this.text_type === "rex_bbcodeText"))
{
var pensMgr = this.inst.copyPensMgr();
var cnt = pensMgr.getLines().length;
var lines = [];
for (var i=0; i<cnt; i++)
{
// get start chart index
var si = pensMgr.getLineStartChartIndex(i);
// get end chart index
var ei = pensMgr.getLineEndChartIndex(i);
var txt = pensMgr.getSliceTagText(si, ei+1);
lines.push(txt);
}
content = lines.join("\n");
}
return content;
};
//////////////////////////////////////
// Conditions
function Cnds() {};
Expand Down Expand Up @@ -249,7 +222,29 @@ cr.behaviors.Rex_text_properties = function(runtime)

Exps.prototype.LineBreakContent = function (ret)
{
ret.set_string( this.lineBreakContent() );
this.drawText();
var content;
if ((this.text_type === "Text") || (this.text_type === "Spritefont2"))
{
content = this.inst.lines.join("\n");
}
else if ((this.text_type === "rex_TagText") || (this.text_type === "rex_bbcodeText"))
{
var pensMgr = this.inst.copyPensMgr();
var cnt = pensMgr.getLines().length;
var lines = [];
for (var i=0; i<cnt; i++)
{
// get start chart index
var si = pensMgr.getLineStartChartIndex(i);
// get end chart index
var ei = pensMgr.getLineEndChartIndex(i);
var txt = pensMgr.getSliceTagText(si, ei+1);
lines.push(txt);
}
content = lines.join("\n");
}
ret.set_string( content );
};

}());
17 changes: 11 additions & 6 deletions behaviors/rex_text_typing/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,24 @@ cr.behaviors.Rex_text_typing = function(runtime)
{
var pensMgr = this.inst.copyPensMgr();
var cnt = pensMgr.getLines().length;
var lines = [];
var addNewLine=false;
content = "";
for (var i=0; i<cnt; i++)
{
if (addNewLine)
content += "\n";

// get start chart index
var si = pensMgr.getLineStartChartIndex(i);
// get end chart index
var ei = pensMgr.getLineEndChartIndex(i);
var txt = pensMgr.getSliceTagText(si, ei+1);
lines.push(txt);
}
content = lines.join("\n");
var txt = pensMgr.getSliceTagText(si, ei+1);

content += txt;
addNewLine = (txt.indexOf("\n") === -1);
}
}
return content;
return content || "";
};

behinstProto.saveToJSON = function ()
Expand Down
8 changes: 8 additions & 0 deletions plugins/rex_achievements/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ cr.plugins_.Rex_Achievements = function(runtime)
AchievementsMgrKlassProto.GetAchievementNameList = function (level_name)
{
var achievements = this.GetAchievementsByLevelName(level_name);
if (!achievements)
return [];

var names = [], names_map = {};
var i,cnt=achievements.length, n;
for(i=0; i<cnt; i++)
Expand Down Expand Up @@ -508,7 +511,12 @@ cr.plugins_.Rex_Achievements = function(runtime)
var get_prop_cond_code = function (prop_name, cond)
{
if (!is_equation(cond))
{
if (isNaN(cond))
cond = '"' + cond + '"';

cond = "==(" + cond + ")";
}
return "(prop['"+prop_name+"']"+cond+")"
}

Expand Down
Loading

0 comments on commit d092fb5

Please sign in to comment.