Skip to content

Commit

Permalink
解决未修改存储板数据仍会触发保存图片的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaofengdiZhu committed Dec 30, 2023
1 parent ee97c96 commit 7b48bf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
22 changes: 13 additions & 9 deletions Gigavolt.Expand/MoreMemoryBanks/ListMemory/GVListMemoryBankData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ public class GVListMemoryBankData : GVArrayData, IEditableItemData {
public List<uint> Data {
get => m_data;
set {
m_updateTime = DateTime.Now;
m_dataChanged = true;
m_data = value;
m_isDataInitialized = value != null;
if (value != m_data) {
m_data = value;
m_updateTime = DateTime.Now;
if (m_isDataInitialized) {
m_dataChanged = true;
}
m_isDataInitialized = value != null;
}
}
}

Expand Down Expand Up @@ -107,7 +111,7 @@ public override void LoadString(string data) {
public override string SaveString() => SaveString(true);

public string SaveString(bool saveLastOutput) {
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();
stringBuilder.Append(m_ID.ToString("X", null));
stringBuilder.Append($";{m_width};{m_height};{m_offset}");
if (saveLastOutput) {
Expand All @@ -131,7 +135,7 @@ public string SaveString(bool saveLastOutput) {
}

public static List<uint> Stream2UintList(Stream stream) {
List<uint> image = new List<uint>((int)(stream.Length / 4 + 1));
List<uint> image = new((int)(stream.Length / 4 + 1));
for (int i = 0; i < stream.Length / 4 + 1; i++) {
byte[] fourBytes = new byte[4];
if (stream.Read(fourBytes, 0, 4) > 0) {
Expand Down Expand Up @@ -187,7 +191,7 @@ public static List<uint> String2UintList(string str, int maxCount = int.MaxValue
public override string Data2String() => m_isDataInitialized ? UintList2String(Data) : null;

public static string UintList2String(List<uint> array, int maxCount = int.MaxValue) {
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();
maxCount = MathUtils.Min(array.Count, maxCount);
for (int i = 0; i < maxCount - 1; i++) {
stringBuilder.Append(array[i].ToString("X", null));
Expand All @@ -200,7 +204,7 @@ public static string UintList2String(List<uint> array, int maxCount = int.MaxVal
}

public static List<uint> Shorts2UintList(short[] shorts) {
List<uint> image = new List<uint>(shorts.Length / 2 + 1);
List<uint> image = new(shorts.Length / 2 + 1);
for (int i = 0; i < image.Count; i++) {
if (i * 2 >= shorts.Length) {
break;
Expand All @@ -225,7 +229,7 @@ public override void Shorts2Data(short[] shorts) {
public static Image UintList2Image(List<uint> list, uint width = 0u, uint height = 0u, uint offset = 0u) {
if (width > 0
&& height > 0) {
Image image = new Image(MathUint.ToInt(width), MathUint.ToInt(height));
Image image = new(MathUint.ToInt(width), MathUint.ToInt(height));
for (int i = (int)offset; i < Math.Min(list.Count, image.Pixels.Length + (int)offset); i++) {
image.Pixels[i].PackedValue = list[i];
}
Expand Down
26 changes: 15 additions & 11 deletions Gigavolt/Block/Store/MemoryBank/GVMemoryBankData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ public class GVMemoryBankData : GVArrayData, IEditableItemData {
public uint[] Data {
get => m_data;
set {
m_updateTime = DateTime.Now;
m_dataChanged = true;
m_data = value;
m_isDataInitialized = value != null;
if (value != m_data) {
m_data = value;
m_updateTime = DateTime.Now;
if (m_isDataInitialized) {
m_dataChanged = true;
}
m_isDataInitialized = value != null;
}
}
}

Expand Down Expand Up @@ -119,7 +123,7 @@ public override void LoadString(string data) {
public override string SaveString() => SaveString(true);

public string SaveString(bool saveLastOutput) {
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();
stringBuilder.Append(m_ID.ToString("X", null));
if (saveLastOutput) {
stringBuilder.Append(';');
Expand All @@ -138,7 +142,7 @@ public string SaveString(bool saveLastOutput) {
}

public static Image String2Image(string data, int width = 0, int height = 0) {
List<uint[]> rowList = new List<uint[]>();
List<uint[]> rowList = new();
int maxColLength = 0;
string[] rows = data.Split(';');
foreach (string row in rows) {
Expand All @@ -154,7 +158,7 @@ public static Image String2Image(string data, int width = 0, int height = 0) {
}
rowList.Add(uints);
}
Image image = new Image(width == 0 ? maxColLength : width, height == 0 ? rows.Length : height);
Image image = new(width == 0 ? maxColLength : width, height == 0 ? rows.Length : height);
for (int i = 0; i < image.Height; i++) {
if (i == rowList.Count) {
break;
Expand All @@ -170,7 +174,7 @@ public static Image String2Image(string data, int width = 0, int height = 0) {
}

public static uint[] String2UintArray(string data, ref int width, ref int height) {
List<uint[]> rowList = new List<uint[]>();
List<uint[]> rowList = new();
int maxColLength = 0;
string[] rows = data.Split(';');
foreach (string row in rows) {
Expand Down Expand Up @@ -222,7 +226,7 @@ public static string Image2String(Image image) {
break;
}
}
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();
for (int j = 0; j < lastNotZero; j++) {
stringBuilder.Append(image.GetPixel(j, i).PackedValue.ToString("X", null));
stringBuilder.Append(',');
Expand All @@ -247,7 +251,7 @@ public static string UintArray2String(uint[] array, uint width, uint height) {
break;
}
}
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();
for (uint j = 0; flag && j < lastNotZero; j++) {
stringBuilder.Append(array[i * width + j].ToString("X", null));
stringBuilder.Append(',');
Expand Down Expand Up @@ -329,7 +333,7 @@ public override void Shorts2Data(short[] shorts) {
}

public static Image UintArray2Image(uint[] array, uint width = 0, uint height = 0) {
Image image = new Image(width == 0 ? array.Length : (int)width, height == 0 ? 1 : (int)height);
Image image = new(width == 0 ? array.Length : (int)width, height == 0 ? 1 : (int)height);
for (int i = 0; i < array.Length; i++) {
image.Pixels[i].PackedValue = array[i];
}
Expand Down

0 comments on commit 7b48bf9

Please sign in to comment.