Skip to content

Commit

Permalink
Merge pull request gritsenko#61 from MikalDev/master
Browse files Browse the repository at this point in the history
feat (color): allow set slot color/dark color to use # hex color code…
  • Loading branch information
MikalDev authored Oct 22, 2021
2 parents 6550d3e + cf6d7ad commit f7c14b8
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 19 deletions.
Binary file added dist/Spine-v1.50.0.c3addon
Binary file not shown.
4 changes: 2 additions & 2 deletions src/aces.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
},
{
"id": "color",
"type": "number"
"type": "any"
}
]
},
Expand All @@ -452,7 +452,7 @@
},
{
"id": "dark-color",
"type": "number"
"type": "any"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "plugin",
"name": "Spine",
"id": "Gritsenko_Spine",
"version": "1.49.0",
"version": "1.50.0",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
60 changes: 48 additions & 12 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,28 @@
return (((val & 0xFF) << 24)
| ((val & 0xFF00) << 8)
| ((val >>> 8) & 0xFF00)
| ((val >>> 24) & 0xFF)) >>> 0;
| ((val >>> 24) & 0xFF));
}

_hexToC3RGBAColorValue(s) {
if (s.length == 7) s = s + 'ff'
const result = this._swap32(parseInt(s.substr(1), 16))
console.log(s,result)
return result;
}

_hexToRGBA(hex) {
var validHEXInput = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if (!validHEXInput) {
return {r:0, g:0, b:0, a:0};
}
var output = {
r: parseInt(validHEXInput[1], 16)/255.0,
g: parseInt(validHEXInput[2], 16)/255.0,
b: parseInt(validHEXInput[3], 16)/255.0,
a: parseInt(validHEXInput[4], 16)/255.0
};
return output;
}

_applySlotColors()
Expand All @@ -1065,11 +1086,19 @@
continue;
}
let color = this.slotColors[slotName];
slot.color.set(
spineBatcher.getRValue(color),
spineBatcher.getGValue(color),
spineBatcher.getBValue(color),
spineBatcher.getAValue(color));
if (typeof color == 'string')
{
if (color.length == 7) color+='ff'
const v = this._hexToRGBA(color);
slot.color.set(v.r, v.g, v.b, v.a)
} else
{
slot.color.set(
spineBatcher.getRValue(color),
spineBatcher.getGValue(color),
spineBatcher.getBValue(color),
spineBatcher.getAValue(color));
}
}

// Set dark colors to slots
Expand All @@ -1085,13 +1114,20 @@
if (slot.darkColor)
{
let color = this.slotDarkColors[slotName];
slot.darkColor.set(
spineBatcher.getRValue(color),
spineBatcher.getGValue(color),
spineBatcher.getBValue(color),
spineBatcher.getAValue(color));
console.log('darkColor, slotName', slotName, Number(this.slotDarkColors[slotName]).toString(16), spineBatcher.getRValue(color), spineBatcher.getAValue(color))
if (typeof color == 'string')
{
if (color.length == 7) color+='ff'
const v = this._hexToRGBA(color);
slot.darkColor.set(v.r, v.g, v.b, v.a)
} else
{
slot.darkColor.set(
spineBatcher.getRValue(color),
spineBatcher.getGValue(color),
spineBatcher.getBValue(color),
spineBatcher.getAValue(color));
}
}
}

this.SetRenderOnce(1.0, true, this.uid);
Expand Down
2 changes: 1 addition & 1 deletion src/c3runtime/spine-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class SpineBatch {
// @ts-ignore
if (!globalThis.spineBatcher)
{
console.log('[Spine] SpineBatcher init, 1.49.0');
console.log('[Spine] SpineBatcher init, 1.50.0');
// @ts-ignore
globalThis.spineBatcher = new SpineBatch();
}
4 changes: 2 additions & 2 deletions src/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
},
"color": {
"name": "Color",
"desc": "Color (use rgba())."
"desc": "Color (use rgba()) or # color."
}
}
},
Expand All @@ -476,7 +476,7 @@
},
"dark-color": {
"name": "Dark color",
"desc": "Dark color (use rgba())."
"desc": "Dark color (use rgba()) or # color."
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const C3 = self.C3;

const PLUGIN_ID = "Gritsenko_Spine";
const PLUGIN_VERSION = "1.49.0";
const PLUGIN_VERSION = "1.50.0";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand Down

0 comments on commit f7c14b8

Please sign in to comment.