Skip to content

Commit

Permalink
Added an example and improve response on missing resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Lizard-13 committed Apr 23, 2018
1 parent b8e0b5d commit 86a3614
Show file tree
Hide file tree
Showing 11 changed files with 1,920 additions and 56 deletions.
1,864 changes: 1,864 additions & 0 deletions Binaries/Output/Release_Windows/Examples/SkeletonTest.gdg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Binaries/Output/Release_Windows/Examples/skeleton.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"SubTexture":[{"frameY":0,"y":234,"frameWidth":112,"frameX":0,"frameHeight":210,"width":111,"height":209,"name":"parts/tailTip","x":456},{"width":112,"y":234,"height":86,"name":"parts/armUpperL","x":340},{"width":48,"y":859,"height":80,"name":"parts/armL","x":373},{"width":96,"y":922,"height":78,"name":"parts/handL","x":1},{"frameY":0,"y":677,"frameWidth":204,"frameX":0,"frameHeight":180,"width":203,"height":180,"name":"parts/legL","x":238},{"frameY":0,"y":397,"frameWidth":236,"frameX":0,"frameHeight":348,"width":235,"height":347,"name":"parts/body","x":1},{"width":216,"y":397,"height":278,"name":"parts/tail","x":238},{"width":208,"y":746,"height":174,"name":"parts/clothes1","x":1},{"width":124,"y":677,"height":282,"name":"parts/hair","x":443},{"frameY":0,"y":1,"frameWidth":338,"frameX":0,"frameHeight":394,"width":337,"height":394,"name":"parts/head","x":1},{"width":28,"y":961,"height":46,"name":"parts/eyeL","x":459},{"frameY":0,"y":961,"frameWidth":38,"frameX":0,"frameHeight":58,"width":37,"height":58,"name":"parts/eyeR","x":420},{"frameY":0,"y":1,"frameWidth":180,"frameX":0,"frameHeight":232,"width":180,"height":231,"name":"parts/legR","x":340},{"width":160,"y":859,"height":94,"name":"parts/armUpperR","x":211},{"frameY":0,"y":941,"frameWidth":46,"frameX":0,"frameHeight":78,"width":45,"height":77,"name":"parts/armR","x":373},{"width":98,"y":322,"height":58,"name":"parts/handR","x":340},{"frameY":0,"y":955,"frameWidth":120,"frameX":0,"frameHeight":36,"width":119,"height":36,"name":"parts/beardL","x":237},{"width":136,"y":955,"height":36,"name":"parts/beardR","x":99}],"width":1024,"height":1024,"name":"dragon","imagePath":"dragon_tex.png"}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gdjs.sk.CocosDataLoader.prototype.getData = function(dataName){
gdjs.sk.CocosDataLoader.prototype.loadDragonBones = function(runtimeScene, objectData){
var textureData = this.getData(objectData.textureDataFilename);
var texture = runtimeScene.getGame().getImageManager().getTexture(objectData.textureName);
if(!textureData || !texture._textureLoaded) return;

for(var i=0; i<textureData.SubTexture.length; i++){
var subTex = textureData.SubTexture[i];
Expand All @@ -28,9 +29,8 @@ gdjs.sk.CocosDataLoader.prototype.loadDragonBones = function(runtimeScene, objec
if (subTex.hasOwnProperty("frameHeight")){
frame.height = subTex.frameHeight;
}

this.textures[subTex.name] = {"texture": texture,
"frame": frame};

this.textures[subTex.name] = {"texture": texture, "frame": frame};
}
};

Expand Down Expand Up @@ -90,7 +90,10 @@ gdjs.sk.SlotCocosRenderer.prototype.getRendererObject = function(){
};

gdjs.sk.SlotCocosRenderer.prototype.loadAsSprite = function(texture){
this.renderer = new cc.Sprite.createWithTexture(texture.texture, texture.frame);
if(!texture)
this.renderer = new cc.Sprite();
else
this.renderer = new cc.Sprite.createWithTexture(texture.texture, texture.frame);
this.renderer.z = 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ gdjs.sk.PixiDataLoader = function()
gdjs.sk.DataLoader = gdjs.sk.PixiDataLoader;

gdjs.sk.PixiDataLoader.prototype.getData = function(dataName){
return PIXI.loader.resources[dataName].data;
if(PIXI.loader.resources[dataName]){
return PIXI.loader.resources[dataName].data;
}
return null;
};

gdjs.sk.PixiDataLoader.prototype.loadDragonBones = function(runtimeScene, objectData){
var textureData = this.getData(objectData.textureDataFilename);
var texture = runtimeScene.getGame().getImageManager().getPIXITexture(objectData.textureName);
if(!textureData || !texture.valid) return;

for(var i=0; i<textureData.SubTexture.length; i++){
var subTex = textureData.SubTexture[i];
Expand All @@ -28,6 +32,12 @@ gdjs.sk.PixiDataLoader.prototype.loadDragonBones = function(runtimeScene, object
if (subTex.hasOwnProperty("frameHeight")){
frame.height = subTex.frameHeight;
}
// Fix the frame size, in case texture is not loaded
if(frame.x > texture.width) frame.x = 0;
if(frame.y > texture.height) frame.y = 0;
if(frame.x + frame.width > texture.width) frame.width = texture.width - frame.x;
if(frame.y + frame.height > texture.height) frame.height = texture.height - frame.y;

this.textures[subTex.name] = new PIXI.Texture(texture.baseTexture, frame=frame);
}
};
Expand Down
7 changes: 7 additions & 0 deletions Extensions/SkeletonObject/Eskarmature.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ gdjs.sk.Armature.prototype.loadData = function(armatureData, skeletalData, debug
this.setRenderers();
};

gdjs.sk.Armature.prototype.setAsRoot = function(){
this.isRoot = true;
// Create an empty shared data, in case nothing is loaded
this.shared = new gdjs.sk.SharedArmature();
this.shared.aabb = [[0,0], [0,0], [0,0], [0,0]];
};

gdjs.sk.Armature.prototype.getRenderer = function(){
return this.renderer;
};
Expand Down
2 changes: 1 addition & 1 deletion Extensions/SkeletonObject/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ void DeclareSkeletonObjectExtension(gd::PlatformExtension & extension)
extension.AddCondition("RaycastSlot",
_("Raycast slot"),
_("Same as Raycast, but intersects specific slots instead."),
_("Raycast _PARAM2_:_PARAM3_ from _PARAM1_;_PARAM2_"),
_("Raycast _PARAM0_:_PARAM1_ from _PARAM2_;_PARAM3_"),
_("Collision"),
"res/conditions/collision24.png",
"res/conditions/collision.png")
Expand Down
70 changes: 23 additions & 47 deletions Extensions/SkeletonObject/Gskeletonruntimeobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gdjs.SkeletonRuntimeObject = function(runtimeScene, objectData){

this.rootArmature = new gdjs.sk.Armature(this);
this.rootArmature.getRenderer().putInScene(this, runtimeScene);
this.rootArmature.isRoot = true;
this.rootArmature.setAsRoot();
this.animationPlaying = true;
this.animationSmooth = true;
this.timeScale = 1.0;
Expand Down Expand Up @@ -91,6 +91,13 @@ gdjs.SkeletonRuntimeObject.prototype.update = function(runtimeScene){
this.rootArmature.update();
};

gdjs.SkeletonRuntimeObject.prototype.getDrawableX = function(){
return this.getX() - this.rootArmature.shared.aabb[0][0] * Math.abs(this.scaleX);
};
gdjs.SkeletonRuntimeObject.prototype.getDrawableY = function(){
return this.getY() - this.rootArmature.shared.aabb[0][1] * Math.abs(this.scaleY);
};

// Object instructions
gdjs.SkeletonRuntimeObject.prototype.getScaleX = function(){
return this.scaleX;
Expand Down Expand Up @@ -322,6 +329,8 @@ gdjs.SkeletonRuntimeObject.prototype.setSlotZOrder = function(slotPath, z){

gdjs.SkeletonRuntimeObject.prototype.isPointInsideSlot = function(slotPath, x, y){
var hitBoxes = this.getPolygons(slotPath);
if(!hitBoxes) return false;

for(var i = 0; i < this.hitBoxes.length; ++i) {
if ( gdjs.Polygon.isPointInside(hitBoxes[i], x, y) )
return true;
Expand All @@ -332,24 +341,17 @@ gdjs.SkeletonRuntimeObject.prototype.isPointInsideSlot = function(slotPath, x, y

// Extension instructions
gdjs.SkeletonRuntimeObject.prototype.raycastSlot = function(slotPath, x, y, angle, dist, closest){
var objW = this.getWidth();
var objH = this.getHeight();
var diffX = this.getDrawableX()+this.getCenterX() - x;
var diffY = this.getDrawableY()+this.getCenterY() - y;
var boundingRadius = Math.sqrt(objW*objW + objH*objH)/2.0;

var result = gdjs.Polygon.raycastTest._statics.result;
result.collision = false;

if ( Math.sqrt(diffX*diffX + diffY*diffY) > boundingRadius + dist )
return result;

var endX = x + dist*Math.cos(angle*Math.PI/180.0);
var endY = y + dist*Math.sin(angle*Math.PI/180.0);
var testSqDist = closest ? dist*dist : 0;

var hitBoxes = this.getPolygons(slotPath);
for (var i=0; i<hitBoxes.length; i++) {
if(!hitBoxes) return result;

for(var i=0; i<hitBoxes.length; i++){
var res = gdjs.Polygon.raycastTest(hitBoxes[i], x, y, endX, endY);
if ( res.collision ) {
if ( closest && (res.closeSqDist < testSqDist) ) {
Expand All @@ -369,26 +371,13 @@ gdjs.SkeletonRuntimeObject.prototype.raycastSlot = function(slotPath, x, y, angl
// Warning!, assuming gdjs.evtTools.object.twoListsTest calls the predicate
// respecting the given objects lists paramenters order
gdjs.SkeletonRuntimeObject.slotObjectCollisionTest = function(skl, obj, slotPath){
//First check if bounding circle are too far.
var o1w = skl.getWidth();
var o1h = skl.getHeight();
var o2w = obj.getWidth();
var o2h = obj.getHeight();

var x = skl.getDrawableX()+skl.getCenterX()-(obj.getDrawableX()+obj.getCenterX());
var y = skl.getDrawableY()+skl.getCenterY()-(obj.getDrawableY()+obj.getCenterY());
var obj1BoundingRadius = Math.sqrt(o1w*o1w+o1h*o1h)/2.0;
var obj2BoundingRadius = Math.sqrt(o2w*o2w+o2h*o2h)/2.0;

if ( Math.sqrt(x*x+y*y) > obj1BoundingRadius + obj2BoundingRadius )
return false;

//Do a real check if necessary.
var hitBoxes1 = skl.getPolygons(slotPath);
if(!hitBoxes1) return false;

var hitBoxes2 = obj.getHitBoxes();
for(var k = 0, lenBoxes1 = hitBoxes1.length;k<lenBoxes1;++k) {
for(var l = 0, lenBoxes2 = hitBoxes2.length;l<lenBoxes2;++l) {
if ( gdjs.Polygon.collisionTest(hitBoxes1[k], hitBoxes2[l]).collision ) {
for(var k=0, lenBoxes1=hitBoxes1.length; k<lenBoxes1; ++k){
for(var l=0, lenBoxes2=hitBoxes2.length; l<lenBoxes2; ++l){
if (gdjs.Polygon.collisionTest(hitBoxes1[k], hitBoxes2[l]).collision){
return true;
}
}
Expand All @@ -398,26 +387,13 @@ gdjs.SkeletonRuntimeObject.slotObjectCollisionTest = function(skl, obj, slotPath
};

gdjs.SkeletonRuntimeObject.slotSlotCollisionTest = function(skl1, skl2, slotPaths){
//First check if bounding circle are too far.
var o1w = skl1.getWidth();
var o1h = skl1.getHeight();
var o2w = skl2.getWidth();
var o2h = skl2.getHeight();

var x = skl1.getDrawableX()+skl1.getCenterX()-(skl2.getDrawableX()+skl2.getCenterX());
var y = skl1.getDrawableY()+skl1.getCenterY()-(skl2.getDrawableY()+skl2.getCenterY());
var obj1BoundingRadius = Math.sqrt(o1w*o1w+o1h*o1h)/2.0;
var obj2BoundingRadius = Math.sqrt(o2w*o2w+o2h*o2h)/2.0;

if ( Math.sqrt(x*x+y*y) > obj1BoundingRadius + obj2BoundingRadius )
return false;

//Do a real check if necessary.
var hitBoxes1 = skl1.getPolygons(slotPaths[0]);
var hitBoxes2 = skl2.getPolygons(slotPaths[1]);
for(var k = 0, lenBoxes1 = hitBoxes1.length;k<lenBoxes1;++k) {
for(var l = 0, lenBoxes2 = hitBoxes2.length;l<lenBoxes2;++l) {
if ( gdjs.Polygon.collisionTest(hitBoxes1[k], hitBoxes2[l]).collision ) {
if(!hitBoxes1 || !hitBoxes2) return false;

for(var k=0, lenBoxes1=hitBoxes1.length; k<lenBoxes1; ++k){
for(var l=0, lenBoxes2=hitBoxes2.length; l<lenBoxes2; ++l){
if (gdjs.Polygon.collisionTest(hitBoxes1[k], hitBoxes2[l]).collision){
return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions Extensions/SkeletonObject/Hskmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ gdjs.SkeletonObjectsManager.prototype.loadSkeleton = function(runtimeScene, obje
var skeleton = {"loader": loader,
"armatures": [],
"rootArmature": 0};

if(!skeletalData) return skeleton;

if(objectData.apiName === "DragonBones"){
// Load sub-textures
Expand Down
6 changes: 3 additions & 3 deletions Extensions/SkeletonObject/JsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class SkeletonObjectJsExtension : public gd::PlatformExtension
conditions["SkeletonObject::PointInsideSlot"].SetFunctionName("isPointInsideSlot");

// Extension instructions
GetAllConditions()["SlotCollidesWithObject"].SetFunctionName("gdjs.sk.slotObjectCollision");
GetAllConditions()["SlotCollidesWithSlot"].SetFunctionName("gdjs.sk.slotSlotCollision");
GetAllConditions()["RaycastSlot"].SetFunctionName("gdjs.sk.raycastSlot");
GetAllConditions()["SkeletonObject::SlotCollidesWithObject"].SetFunctionName("gdjs.sk.slotObjectCollision");
GetAllConditions()["SkeletonObject::SlotCollidesWithSlot"].SetFunctionName("gdjs.sk.slotSlotCollision");
GetAllConditions()["SkeletonObject::RaycastSlot"].SetFunctionName("gdjs.sk.raycastSlot");

GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION();
};
Expand Down

0 comments on commit 86a3614

Please sign in to comment.