Bunny83 / SimpleJSON

A simple JSON parser in C#
MIT License
735 stars 294 forks source link

Update SimpleJSONUnity.cs #35

Closed ziobernamac closed 3 years ago

ziobernamac commented 3 years ago

If Alpha not specified (rgb array) create color with default opacity set to maximum

Thanks for your great job!!

david-pfx commented 3 years ago

I support the change, but I can't review it, because there are 3000 changes (insertions _+ deletions). Why is that?

And was this really the only useful change you could think of?

ziobernamac commented 3 years ago

Sorry about the mess in changes...I can't explain what appened..I've only pasted 10 lines of code in web page of git... I've modified only these 2 functions in region color/color32

public Color ReadColor(Color aDefault) { if (IsObject) return new Color(this["a"].AsFloat, this["r"].AsFloat, this["g"].AsFloat, this["b"].AsFloat); if (IsArray) { if (this.Count==3) return new Color(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat, 1); else if(this.Count==4) return new Color(this[0].AsFloat, this[1].AsFloat, this[2].AsFloat, this[3].AsFloat); else Debug.LogError("Unable to parse color..."); } return aDefault; }

public Color32 ReadColor32(Color32 aDefault) { if (IsObject) return new Color32((byte)this["r"].AsInt, (byte)this["g"].AsInt, (byte)this["b"].AsInt, (byte)this["a"].AsInt); if (IsArray) { if (this.Count == 3) return new Color32((byte)this[0].AsInt, (byte)this[1].AsInt, (byte)this[2].AsInt, 255); else if (this.Count == 4) return new Color32((byte)this[0].AsInt, (byte)this[1].AsInt, (byte)this[2].AsInt, (byte)this[3].AsInt); else Debug.LogError("Unable to parse color..."); } return aDefault; }

ziobernamac commented 3 years ago

..as I see in public Color ReadColor(Color aDefault)

the order in new Color is wrong... r,g,b,a.. You wrote a,r,g,b..

Bunny83 commented 3 years ago

Thanks for the pull request. I've noticed the wrong component order and fixed it :) I also added proper default values for colors without an alpha component. You can now specify what default value you want in a static variable. Your changes only affected "colors as array" but you ignored the "color as object" case. I've implemented the default values for both. baed3f9423174904e784902faf6291bdde9d4287