Commit e23830ed authored by lijin's avatar lijin

重整結構

parent 0afe8bd5
......@@ -35,61 +35,60 @@ public class GameEditor
}
Directory.CreateDirectory(path);
ResData rd = new ResData();
rd.name = Selection.activeObject.name;
Debug.Log(path + ".png");
rd.png = AssetDatabase.LoadAssetAtPath<Texture2D>(path + ".png");
rd.jpg = AssetDatabase.LoadAssetAtPath<Texture2D>(path + "_pictureColorThn4.jpg");
rd.preview = AssetDatabase.LoadAssetAtPath<Texture2D>(path + "_pictureThn4.png");
ResData redData = new ResData();
redData.name = Selection.activeObject.name;
redData.png = AssetDatabase.LoadAssetAtPath<Texture2D>(path + ".png");
redData.jpg = AssetDatabase.LoadAssetAtPath<Texture2D>(path + "_pictureColorThn4.jpg");
redData.preview = AssetDatabase.LoadAssetAtPath<Texture2D>(path + "_pictureThn4.png");
FileStream fs = new FileStream(path + ".json", FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
string str = sr.ReadToEnd();
rd.json = JsonUtility.FromJson<ResJsonData>(str);
redData.json = JsonUtility.FromJson<ResJsonData>(str);
sr.Close();
fs.Close();
Color[] c = rd.png.GetPixels();
rd.png = new Texture2D(rd.png.width, rd.png.height, rd.png.format, false);
rd.png.SetPixels(c);
List<short> l = new List<short>();
for (int i = 0; i < 2048 * 2048; i++)
{
l.Add(-1);
}
for (int i = 0; i < rd.json.roomDatas.Count; i++)
Color[] c = redData.png.GetPixels();
redData.png = new Texture2D(redData.png.width, redData.png.height, redData.png.format, false);
redData.png.SetPixels(c);
for (int i = 0; i < redData.json.roomGroupsData.Count; i++)
{
FunDo(l, rd.png, rd.json.roomDatas[i]);
for (int j = 0; j < redData.json.roomGroupsData[i].roomIds.Count; j++)
{
RoomDatas rd = redData.json.roomDatas[redData.json.roomGroupsData[i].roomIds[j]];
rd.groupId = i + 1;
FunDo(redData, rd);
}
}
rd.png.Apply();
rd.json.allPos = l.ToList();
redData.png.Apply();
File.WriteAllBytes(path + "/" + rd.name + "_png.png", rd.png.EncodeToPNG());
File.WriteAllBytes(path + "/" + rd.name + "_jpg.jpg", rd.jpg.EncodeToJPG());
File.WriteAllBytes(path + "/" + rd.name + "_preview.png", rd.preview.EncodeToPNG());
File.WriteAllBytes(path + "/" + redData.name + "_png.png", redData.png.EncodeToPNG());
File.WriteAllBytes(path + "/" + redData.name + "_jpg.jpg", redData.jpg.EncodeToJPG());
File.WriteAllBytes(path + "/" + redData.name + "_preview.png", redData.preview.EncodeToPNG());
string savePath = path + "/" + rd.name + "_json.bin";
string savePath = path + "/" + redData.name + "_json.bin";
FileStream saveFs = File.Open(savePath, FileMode.Create);
BinaryFormatter saveBf = new BinaryFormatter();
saveBf.Serialize(saveFs, rd.json);
saveBf.Serialize(saveFs, redData.json);
saveFs.Close();
string saveDynamicPath = path + "/" + rd.name + "_dynamic.bin";
string saveDynamicPath = path + "/" + redData.name + "_dynamic.bin";
FileStream saveDynamicFs = File.Open(saveDynamicPath, FileMode.Create);
BinaryFormatter saveDynamicBf = new BinaryFormatter();
saveDynamicBf.Serialize(saveDynamicFs, rd.dynamic);
saveDynamicBf.Serialize(saveDynamicFs, redData.dynamic);
saveDynamicFs.Close();
Debug.Log("成功:" + savePath);
}
public static void FunDo(List<short> l, Texture2D png, RoomDatas rd)
public static void FunDo(ResData redData, RoomDatas rd)
{
Texture2D png = redData.png;
V2 v = new V2(rd.px, rd.py);
Stack<V2> stackVector2 = new Stack<V2>();
if (rd.valid == 0)
{
Debug.Log("壞點:" + v.x + "-" + v.y);
png.SetPixel(v.x, v.y, Color.clear);
Debug.LogError("壞點:" + v.x + "-" + v.y);
return;
}
else
......@@ -99,13 +98,12 @@ public class GameEditor
V2[] d = new V2[8] { new V2(0, -1), new V2(0, 1), new V2(-1, 0), new V2(1, 0), new V2(-1, -1), new V2(-1, 1), new V2(1, -1), new V2(1, 1) };
V2 v_1;
V2 v_2;
int count = 0;
while (stackVector2.Count > 0)
{
v_1 = stackVector2.Pop();
png.SetPixel(v_1.x, v_1.y, Color.white);
l[v_1.x + v_1.y * png.width] = (short)rd.id;
rd.posIndex.Add((short)(v_1.x + v_1.y * png.width));
for (int i = 0; i < d.Length; i++)
{
v_2 = v_1 + d[i];
......
......@@ -212,4 +212,8 @@ public class GameMgr : MonoBehaviour
{
md.Save();
}
public void AutoClick()
{
md.AutoClick();
}
}
......@@ -70,8 +70,7 @@ public class MainData : MonoBehaviour
//Debug.Log("涂过了");
return false;
}
int id = json.allPos[(int)(v.x + v.y * png.width)];
if (FunDo(id, v, b))
if (FunDo(v, b))
{
sw.Stop();
Debug.Log("耗时:" + sw.ElapsedMilliseconds);
......@@ -79,36 +78,47 @@ public class MainData : MonoBehaviour
}
return false;
}
public bool FunDo(int id, Vector2 v, bool b = false)
public bool FunDo(Vector2 v, bool b = false)
{
for (int i = 0; i < json.roomGroupsData.Count; i++)
RoomDatas rd = null;
for (int i = 0; i < json.roomDatas.Count; i++)
{
RoomGroupsData rgd = json.roomGroupsData[i];
if (rgd.roomIds.Contains(id))
List<short> l = json.roomDatas[i].posIndex;
for (int j = 0; j < l.Count; j++)
{
if (rgd.id == curGroupId || b)
if (l[j] == v.x + v.y * png.width)
{
ExRoomDatas erd = new ExRoomDatas();
dynamic.AddData(rgd.id, id);
Color[] c_png = png.GetPixels();
for (int j = 0; j < json.allPos.Count; j++)
{
if (json.allPos[j] == id)
{
erd.AddData(j, png.width);
c_png[j] = Color.clear;
}
}
png.SetPixels(c_png);
png.Apply();
GameMgr.Ins.eiMgr.Create(new Color(rgd.R / 255f, rgd.G / 255f, rgd.B / 255f, 1), v);
GameMgr.Ins.tiMgr.CircleId(id);
GameMgr.Ins.miMgr.Play(v, id);
EventDispatcher.Dispatch(EventName.Event.Event_GropuItemChange, json.roomGroupsData[i], dynamic);
return true;
rd = json.roomDatas[i];
}
}
}
if (rd == null)
{
Debug.LogError("沒找到點:" + v.x + "-" + v.y);
return false;
}
if (dynamic.step.Contains(rd.id))
{
Debug.LogError("點過了:" + rd.id);
return false;
}
if (rd.groupId == curGroupId || b)
{
dynamic.AddData(rd.groupId, rd.id);
Color[] c_png = png.GetPixels();
for (int i = 0; i < rd.posIndex.Count; i++)
{
c_png[rd.posIndex[i]] = Color.clear;
}
png.SetPixels(c_png);
png.Apply();
RoomGroupsData rgd = json.roomGroupsData[rd.groupId - 1];
GameMgr.Ins.eiMgr.Create(new Color(rgd.R / 255f, rgd.G / 255f, rgd.B / 255f, 1), v);
GameMgr.Ins.tiMgr.CircleId(rd.id);
GameMgr.Ins.miMgr.Play(v, rd.id);
EventDispatcher.Dispatch(EventName.Event.Event_GropuItemChange, rgd, dynamic);
return true;
}
return false;
}
......@@ -124,39 +134,20 @@ public class MainData : MonoBehaviour
{
return;
}
curGroupId = id;
List<int> list = new List<int>();
List<RoomGroupsData> l = json.roomGroupsData;
for (int i = 0; i < l.Count; i++)
{
if (l[i].id == id)
{
list = l[i].roomIds;
break;
}
}
GameMgr.Ins.miMgr.CircleAll();
Dictionary<int, ExRoomDatas> dic = new Dictionary<int, ExRoomDatas>();
for (int i = 0; i < list.Count; i++)
{
if (!dynamic.step.Contains(list[i]))
{
dic.Add(list[i], new ExRoomDatas());
}
}
for (int i = 0; i < json.allPos.Count; i++)
{
if (dic.ContainsKey(json.allPos[i]))
{
dic[json.allPos[i]].AddData(i, png.width);
}
}
for (int i = 0; i < list.Count; i++)
curGroupId = id;
List<int> roomIds = json.roomGroupsData[curGroupId - 1].roomIds;
for (int i = 0; i < roomIds.Count; i++)
{
if (dic.ContainsKey(list[i]))
RoomDatas rd = json.roomDatas[roomIds[i]];
if (!dynamic.step.Contains(rd.id))
{
GameMgr.Ins.miMgr.Create(this, dic[list[i]], list[i], id);
ExRoomDatas erd = new ExRoomDatas();
for (int j = 0; j < rd.posIndex.Count; j++)
{
erd.AddData(rd.posIndex[j], png.width);
}
GameMgr.Ins.miMgr.Create(this, erd, rd.id, rd.groupId);
}
}
EventDispatcher.Dispatch(EventName.Event.Event_ChoiseGroupByPic, curGroupId);
......@@ -179,15 +170,24 @@ public class MainData : MonoBehaviour
//Debug.Log("涂过了");
return;
}
int id = json.allPos[(int)(v.x + v.y * png.width)];
for (int i = 0; i < json.roomGroupsData.Count; i++)
RoomDatas rd = null;
for (int i = 0; i < json.roomDatas.Count; i++)
{
if (json.roomGroupsData[i].roomIds.Contains(id))
List<short> l = json.roomDatas[i].posIndex;
for (int j = 0; j < l.Count; j++)
{
ChooseGroup(json.roomGroupsData[i].id);
if (l[j] == v.x + v.y * png.width)
{
rd = json.roomDatas[i];
}
}
}
if (rd == null)
{
Debug.LogError("沒找到點:" + v.x + "-" + v.y);
return;
}
ChooseGroup(rd.groupId);
}
public void Clear()
......@@ -208,21 +208,15 @@ public class MainData : MonoBehaviour
public void RePlay()
{
ChooseGroup();
Dictionary<int, ExRoomDatas> dic = new Dictionary<int, ExRoomDatas>();
for (int i = 0; i < dynamic.step.Count; i++)
{
dic.Add(dynamic.step[i], new ExRoomDatas());
}
for (int i = 0; i < json.allPos.Count; i++)
{
if (dic.ContainsKey(json.allPos[i]))
RoomDatas rd = json.roomDatas[dynamic.step[i]];
ExRoomDatas erd = new ExRoomDatas();
for (int j = 0; j < rd.posIndex.Count; i++)
{
dic[json.allPos[i]].AddData(i, png.width);
erd.AddData(rd.posIndex[j], png.width);
}
}
for (int i = 0; i < dynamic.step.Count; i++)
{
GameMgr.Ins.miMgr.Create(this, dic[dynamic.step[i]], dynamic.step[i], 0);
GameMgr.Ins.miMgr.Create(this, erd, rd.id, rd.groupId);
}
}
......@@ -230,4 +224,16 @@ public class MainData : MonoBehaviour
{
SaveManager.Instance.SaveRes(key, dynamic, png);
}
public void AutoClick()
{
List<int> list = json.roomGroupsData[curGroupId - 1].roomIds;
for (int i = 0; i < list.Count; i++)
{
if (!dynamic.step.Contains(list[i]))
{
OnClickPos(new Vector2(json.roomDatas[list[i]].px, json.roomDatas[list[i]].py));
}
}
}
}
\ No newline at end of file
using System;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
......@@ -57,9 +58,6 @@ public class DynamicGroupsData
[Serializable]
public class ResJsonData
{
public List<short> allPos = new List<short>();
public List<RoomDatas> roomDatas = new List<RoomDatas>();
public List<RoomGroupsData> roomGroupsData = new List<RoomGroupsData>();
......@@ -92,6 +90,9 @@ public class ExtraMetaData //后面再看为啥json序列化失败
[Serializable]
public class RoomDatas
{
public int groupId = -1;
public List<short> posIndex = new List<short>();
public int id;
public int valid;
public int notPaintCol;
......
......@@ -365,8 +365,7 @@ public class GroupListManager : MonoBehaviour
//自动涂的按钮
public void AutoFullArea_Btn()
{
Debug.Log("点提示");
GameMgr.Ins.AutoClick();
EventDispatcher.Dispatch(EventName.Event.Event_AutoFullArea);
}
......
......@@ -70,7 +70,6 @@ public class SaveManager : MonoBehaviour
//二进制反序列化
BinaryFormatter bf = new BinaryFormatter();
ResJsonData test = (ResJsonData)bf.Deserialize(stream);
Debug.Log("test" + test.allPos.Count + " name=" + test.height);
}
public void SaveRes(string key, DynamicData data, Texture2D png)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment