Add frame list in skin data structure. Remove Cocos2d Plist support.
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 925f95cb7c6644a4695b2701d42e1ea2
|
||||
folderAsset: yes
|
||||
timeCreated: 1606989037
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Common.Plist {
|
||||
public class PlistConvert {
|
||||
public static T Deserialize<T>(string file) {
|
||||
return (T)Deserialize(typeof(T), PlistCS.Plist.readPlist(file));
|
||||
}
|
||||
|
||||
public static object Deserialize(Type type, object obj, Binder binder = null) {
|
||||
if (binder == null)
|
||||
binder = BinderAttribute.CreateBinderOfType(type);
|
||||
if (obj is IList) {
|
||||
var lobj = (List<object>)obj;
|
||||
foreach (var i in lobj) {
|
||||
throw new NotImplementedException(); // TODO
|
||||
}
|
||||
}
|
||||
else if (obj is IDictionary) {
|
||||
var dobj = (Dictionary<string, object>)obj;
|
||||
if (typeof(IDictionary).IsAssignableFrom(type)) {
|
||||
var result = (IDictionary)ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
var it = type.GetGenericArguments()[1];
|
||||
foreach (var i in dobj) {
|
||||
var value = Deserialize(it, i.Value, binder);
|
||||
result.Add(i.Key, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
foreach (var i in dobj) {
|
||||
var imis = type.GetMember(i.Key);
|
||||
if (imis.Length == 0) continue;
|
||||
var imi = imis[0];
|
||||
var it = ReflectionHelper.GetMemberType(imi);
|
||||
var value = Deserialize(it, i.Value, binder);
|
||||
ReflectionHelper.SetValue(imi, result, value, binder);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else return obj;
|
||||
throw new Exception(); // TODO
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bc71e8b62d4022409aa5518bbf3a7d8
|
||||
timeCreated: 1608801352
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,7 +1,6 @@
|
||||
#define BUILD
|
||||
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Plist;
|
||||
using Cryville.Crtr.Config;
|
||||
using Cryville.Crtr.Event;
|
||||
using Newtonsoft.Json;
|
||||
@@ -26,8 +25,7 @@ namespace Cryville.Crtr {
|
||||
Ruleset ruleset;
|
||||
PdtRuleset pruleset;
|
||||
Dictionary<string, Texture2D> texs;
|
||||
public static Dictionary<string, Cocos2dFrames.Frame> frames;
|
||||
List<Cocos2dFrames> plists;
|
||||
public static Dictionary<string, SpriteFrame> frames;
|
||||
|
||||
readonly Queue<string> texLoadQueue = new Queue<string>();
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
@@ -353,6 +351,13 @@ namespace Cryville.Crtr {
|
||||
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
|
||||
);
|
||||
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
|
||||
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
|
||||
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (skin.format != 1) throw new FormatException("Invalid skin file version");
|
||||
}
|
||||
|
||||
loadThread = new Thread(new ParameterizedThreadStart(Load));
|
||||
loadThread.Start(new LoadInfo() {
|
||||
chartFile = chartFile,
|
||||
@@ -363,10 +368,10 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 0, "Load/MainThread", "Loading textures...");
|
||||
texloadtimer = new diag::Stopwatch();
|
||||
texloadtimer.Start();
|
||||
frames = new Dictionary<string, SpriteFrame>();
|
||||
texs = new Dictionary<string, Texture2D>();
|
||||
var flist = skinFile.Directory.GetFiles("*.png");
|
||||
foreach (FileInfo f in flist) {
|
||||
texLoadQueue.Enqueue(f.FullName);
|
||||
foreach (var f in skin.frames) {
|
||||
texLoadQueue.Enqueue(Path.Combine(skinFile.Directory.FullName, f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,13 +380,12 @@ namespace Cryville.Crtr {
|
||||
diag::Stopwatch timer = new diag::Stopwatch();
|
||||
timer.Reset(); timer.Start();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
||||
foreach (var i in plists) i.Init(texs);
|
||||
foreach (var t in texs) {
|
||||
if (frames.ContainsKey(t.Key)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
||||
continue;
|
||||
}
|
||||
var f = new Cocos2dFrames.Frame(t.Value);
|
||||
var f = new SpriteFrame(t.Value);
|
||||
f.Init();
|
||||
frames.Add(t.Key, f);
|
||||
}
|
||||
@@ -559,23 +563,9 @@ namespace Cryville.Crtr {
|
||||
void LoadSkin(FileInfo file) {
|
||||
DirectoryInfo dir = file.Directory;
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (skin.format != 1) throw new FormatException("Invalid skin file version");
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
}
|
||||
plists = new List<Cocos2dFrames>();
|
||||
frames = new Dictionary<string, Cocos2dFrames.Frame>();
|
||||
foreach (FileInfo f in file.Directory.GetFiles("*.plist")) {
|
||||
var pobj = PlistConvert.Deserialize<Cocos2dFrames>(f.FullName);
|
||||
plists.Add(pobj);
|
||||
foreach (var i in pobj.frames)
|
||||
frames.Add(StringUtils.TrimExt(i.Key), i.Value);
|
||||
}
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@@ -1,176 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
[BinderAttribute(typeof(Cocos2dFramesBinder))]
|
||||
public class Cocos2dFrames {
|
||||
public Metadata metadata;
|
||||
public class Metadata {
|
||||
public int format;
|
||||
public Vector2 size;
|
||||
public string textureFileName;
|
||||
}
|
||||
|
||||
public Dictionary<string, Frame> frames;
|
||||
public class Frame {
|
||||
#pragma warning disable IDE1006
|
||||
Rect _frame;
|
||||
public Rect frame {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
public Rect textureRect {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
|
||||
bool _rotated = false;
|
||||
public bool rotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
public bool textureRotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public Vector2 offset;
|
||||
|
||||
public Rect sourceColorRect;
|
||||
public Vector2 sourceSize;
|
||||
private Rect _uv;
|
||||
private Vector2[] cuv;
|
||||
public Rect UV {
|
||||
get {
|
||||
return _uv;
|
||||
}
|
||||
private set {
|
||||
_uv = value;
|
||||
float x0 = Mathf.Min(_uv.xMin, _uv.xMax);
|
||||
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
|
||||
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
|
||||
float y1 = Mathf.Max(_uv.yMin, _uv.yMax);
|
||||
if (_rotated) cuv = new Vector2[]{
|
||||
new Vector2(x0, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
};
|
||||
else cuv = new Vector2[]{
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y1),
|
||||
};
|
||||
}
|
||||
}
|
||||
public Vector2 GetUV(Vector2 uv) {
|
||||
return GetUV(uv.x, uv.y);
|
||||
}
|
||||
public Vector2 GetUV(float u, float v) {
|
||||
Vector2 uv00 = cuv[0], uv11 = cuv[1],
|
||||
uv10 = cuv[2], uv01 = cuv[3];
|
||||
return (1 - u - v) * uv00
|
||||
+ u * uv10
|
||||
+ v * uv01
|
||||
+ u * v * (uv00 + uv11 - uv10 - uv01);
|
||||
}
|
||||
public Texture2D Texture {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Vector2 Size {
|
||||
get {
|
||||
return new Vector2(Texture.width, Texture.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
if (Texture == null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
_frame = new Rect(Vector2.zero, Size);
|
||||
var w = _frame.width;
|
||||
var h = _frame.height;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
|
||||
public void Init(int w, int h, Texture2D _base) {
|
||||
if (Texture != null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
Texture = _base;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
public Frame() { }
|
||||
public Frame(Texture2D tex) {
|
||||
Texture = tex;
|
||||
}
|
||||
}
|
||||
|
||||
Texture2D _base;
|
||||
|
||||
public void Init(Dictionary<string, Texture2D> texs) {
|
||||
_base = texs[StringUtils.TrimExt(metadata.textureFileName)];
|
||||
var w = (int)metadata.size.x;
|
||||
var h = (int)metadata.size.y;
|
||||
if (w == 0 || h == 0) {
|
||||
w = _base.width;
|
||||
h = _base.height;
|
||||
}
|
||||
foreach (var f in frames) {
|
||||
f.Value.Init(w, h, _base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Cocos2dFramesBinder : EmptyBinder {
|
||||
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
||||
if (value is string) {
|
||||
var str = (string)value;
|
||||
if (type == typeof(Rect)) {
|
||||
var m = Regex.Match(str, @"^{({.*?}),({.*?})}$");
|
||||
var p = (Vector2)ChangeType(m.Groups[1].Value, typeof(Vector2), culture);
|
||||
var s = (Vector2)ChangeType(m.Groups[2].Value, typeof(Vector2), culture);
|
||||
return new Rect(p, s);
|
||||
}
|
||||
else if (type == typeof(Vector2)) {
|
||||
var m = Regex.Match(str, @"^{(.*?),(.*?)}$");
|
||||
var w = float.Parse(m.Groups[1].Value);
|
||||
var h = float.Parse(m.Groups[2].Value);
|
||||
return new Vector2(w, h);
|
||||
}
|
||||
}
|
||||
else if (typeof(IDictionary).IsAssignableFrom(value.GetType())) {
|
||||
var dict = (IDictionary)value;
|
||||
if (type == typeof(Rect)) {
|
||||
var x = float.Parse((string)dict["x"]);
|
||||
var y = float.Parse((string)dict["y"]);
|
||||
var w = float.Parse((string)dict["w"]);
|
||||
var h = float.Parse((string)dict["h"]);
|
||||
return new Rect(x, y, w, h);
|
||||
}
|
||||
else if (type == typeof(Vector2)) {
|
||||
var w = float.Parse((string)dict["w"]);
|
||||
var h = float.Parse((string)dict["h"]);
|
||||
return new Vector2(w, h);
|
||||
}
|
||||
}
|
||||
return base.ChangeType(value, type, culture);
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ using Logger = Cryville.Common.Logger;
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteInfo {
|
||||
public string FrameName;
|
||||
public Cocos2dFrames.Frame Frame {
|
||||
public SpriteFrame Frame {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
@@ -23,6 +23,8 @@ namespace Cryville.Crtr {
|
||||
[JsonRequired]
|
||||
public string pdt;
|
||||
|
||||
public List<string> frames = new List<string>();
|
||||
|
||||
[JsonIgnore]
|
||||
public PdtSkin Root { get; private set; }
|
||||
|
||||
|
109
Assets/Cryville/Crtr/SpriteFrame.cs
Normal file
109
Assets/Cryville/Crtr/SpriteFrame.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class SpriteFrame {
|
||||
#pragma warning disable IDE1006
|
||||
Rect _frame;
|
||||
public Rect frame {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
public Rect textureRect {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
|
||||
bool _rotated = false;
|
||||
public bool rotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
public bool textureRotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public Vector2 offset;
|
||||
|
||||
public Rect sourceColorRect;
|
||||
public Vector2 sourceSize;
|
||||
private Rect _uv;
|
||||
private Vector2[] cuv;
|
||||
public Rect UV {
|
||||
get {
|
||||
return _uv;
|
||||
}
|
||||
private set {
|
||||
_uv = value;
|
||||
float x0 = Mathf.Min(_uv.xMin, _uv.xMax);
|
||||
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
|
||||
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
|
||||
float y1 = Mathf.Max(_uv.yMin, _uv.yMax);
|
||||
if (_rotated) cuv = new Vector2[]{
|
||||
new Vector2(x0, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
};
|
||||
else cuv = new Vector2[]{
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y1),
|
||||
};
|
||||
}
|
||||
}
|
||||
public Vector2 GetUV(Vector2 uv) {
|
||||
return GetUV(uv.x, uv.y);
|
||||
}
|
||||
public Vector2 GetUV(float u, float v) {
|
||||
Vector2 uv00 = cuv[0], uv11 = cuv[1],
|
||||
uv10 = cuv[2], uv01 = cuv[3];
|
||||
return (1 - u - v) * uv00
|
||||
+ u * uv10
|
||||
+ v * uv01
|
||||
+ u * v * (uv00 + uv11 - uv10 - uv01);
|
||||
}
|
||||
public Texture2D Texture {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Vector2 Size {
|
||||
get {
|
||||
return new Vector2(Texture.width, Texture.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
if (Texture == null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
_frame = new Rect(Vector2.zero, Size);
|
||||
var w = _frame.width;
|
||||
var h = _frame.height;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
|
||||
public void Init(int w, int h, Texture2D _base) {
|
||||
if (Texture != null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
Texture = _base;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
public SpriteFrame() { }
|
||||
public SpriteFrame(Texture2D tex) {
|
||||
Texture = tex;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user