Skip to content

Commit

Permalink
Minor API changes for map/dplc loading/saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Mar 5, 2015
1 parent 29baff4 commit 2e3a10b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SonAni/MainForm.cs
Expand Up @@ -27,7 +27,7 @@ public MainForm()
byte[] tiles;
ColorPalette palette;
List<MappingsFrame> mappings;
DPLCFrame[] dplc;
List<DPLCFrame> dplc;
string animlabel;
List<Animation> animations;
List<Sprite> sprites;
Expand Down
6 changes: 3 additions & 3 deletions SonLVL/MainForm.cs
Expand Up @@ -443,11 +443,11 @@ private void LevelToolStripMenuItem_Clicked(object sender, EventArgs e)
map = MappingsFrame.Load(File.ReadAllBytes(Path.Combine(anipath, anim.MappingsFile)), anim.MappingsGame);
else
map = MappingsFrame.LoadASM(Path.Combine(anipath, anim.MappingsFile), anim.MappingsGame);
DPLCFrame[] dplc;
List<DPLCFrame> dplc;
if (anim.DPLCFormat == MappingsFormat.Binary)
dplc = DPLCFrame.Load(File.ReadAllBytes(Path.Combine(anipath, anim.DPLCFile)), anim.DPLCGame);
else
dplc = DPLCFrame.LoadASM(Path.Combine(anipath, anim.DPLCFile), anim.DPLCGame).ToArray();
dplc = DPLCFrame.LoadASM(Path.Combine(anipath, anim.DPLCFile), anim.DPLCGame);
Animation ani;
if (anim.AnimationFormat == MappingsFormat.Binary)
ani = new Animation(File.ReadAllBytes(Path.Combine(anipath, anim.AnimationFile)), 0, "Animation");
Expand All @@ -462,7 +462,7 @@ private void LevelToolStripMenuItem_Clicked(object sender, EventArgs e)
pal[item.Destination + i] = c[i].RGBColor;
}
pal[0] = Color.Transparent;
loadingAnimation1.ChangeAnimation(tiles.ToArray(), map.ToArray(), dplc, ani, pal);
loadingAnimation1.ChangeAnimation(tiles.ToArray(), map.ToArray(), dplc.ToArray(), ani, pal);
#if !DEBUG
loadingAnimation1.BringToFront();
loadingAnimation1.Show();
Expand Down
35 changes: 18 additions & 17 deletions SonLVLAPI/DataTypes.cs
Expand Up @@ -1570,7 +1570,7 @@ public static void ToASM(string file, NamedList<MappingsFrame> frames, EngineVer
ToASM(file, frames.Name, frames, version, macros);
}

public static void ToASM(string file, string name, List<MappingsFrame> frames, EngineVersion version, bool macros)
public static void ToASM(string file, string name, IList<MappingsFrame> frames, EngineVersion version, bool macros)
{
using (FileStream stream = new FileStream(file, FileMode.Create, FileAccess.Write))
using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII))
Expand Down Expand Up @@ -1666,12 +1666,12 @@ public static void ToASM(string file, string name, List<MappingsFrame> frames, E

}

public static byte[] GetBytes(MappingsFrame[] maps, EngineVersion version)
public static byte[] GetBytes(IList<MappingsFrame> maps, EngineVersion version)
{
int off = maps.Length * 2;
List<short> offs = new List<short>(maps.Length);
int off = maps.Count * 2;
List<short> offs = new List<short>(maps.Count);
List<byte> mapbytes = new List<byte>();
for (int i = 0; i < maps.Length; i++)
for (int i = 0; i < maps.Count; i++)
if (i == 0 & maps[i].TileCount == 0)
offs.Add(0);
else
Expand All @@ -1687,9 +1687,9 @@ public static byte[] GetBytes(MappingsFrame[] maps, EngineVersion version)
if (found) continue;
offs.Add((short)off);
mapbytes.AddRange(maps[i].GetBytes(version));
off = maps.Length * 2 + mapbytes.Count;
off = maps.Count * 2 + mapbytes.Count;
}
List<byte> result = new List<byte>(maps.Length * 2 + mapbytes.Count);
List<byte> result = new List<byte>(maps.Count * 2 + mapbytes.Count);
foreach (short item in offs)
result.AddRange(ByteConverter.GetBytes(item));
result.AddRange(mapbytes);
Expand Down Expand Up @@ -1799,12 +1799,12 @@ public static NamedList<DPLCFrame> LoadASM(string file, EngineVersion version)
return new NamedList<DPLCFrame>(labels.GetKeyOrDefault(0, Path.GetFileNameWithoutExtension(file).MakeIdentifier()), Load(bin, version, labels));
}

public static DPLCFrame[] Load(byte[] file, EngineVersion version)
public static List<DPLCFrame> Load(byte[] file, EngineVersion version)
{
return Load(file, version, null);
}

public static DPLCFrame[] Load(byte[] file, EngineVersion version, Dictionary<string, int> labels)
public static List<DPLCFrame> Load(byte[] file, EngineVersion version, Dictionary<string, int> labels)
{
int[] addresses = LevelData.GetOffsetList(file);
List<DPLCFrame> result = new List<DPLCFrame>();
Expand All @@ -1817,7 +1817,7 @@ public static DPLCFrame[] Load(byte[] file, EngineVersion version, Dictionary<st
name = label.Key;
result.Add(new DPLCFrame(file, item, version, name));
}
return result.ToArray();
return result;
}

public DPLCFrame(string name)
Expand Down Expand Up @@ -1859,7 +1859,7 @@ public static void ToASM(string file, NamedList<DPLCFrame> frames, EngineVersion
ToASM(file, frames.Name, frames, version, macros, s3kp);
}

public static void ToASM(string file, string name, List<DPLCFrame> frames, EngineVersion version, bool macros, bool s3kp)
public static void ToASM(string file, string name, IList<DPLCFrame> frames, EngineVersion version, bool macros, bool s3kp)
{
using (FileStream stream = new FileStream(file, FileMode.Create, FileAccess.Write))
using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII))
Expand Down Expand Up @@ -1895,6 +1895,7 @@ public static void ToASM(string file, string name, List<DPLCFrame> frames, Engin
}
else
{
if (s3kp) version = EngineVersion.S2;
List<string> writtenFrames = new List<string>();
writer.WriteLine(name + ":");
foreach (DPLCFrame frame in frames)
Expand Down Expand Up @@ -1948,12 +1949,12 @@ public static void ToASM(string file, string name, List<DPLCFrame> frames, Engin
}
}

public static byte[] GetBytes(DPLCFrame[] dplcs, EngineVersion version)
public static byte[] GetBytes(IList<DPLCFrame> dplcs, EngineVersion version)
{
int off = dplcs.Length * 2;
List<short> offs = new List<short>(dplcs.Length);
int off = dplcs.Count * 2;
List<short> offs = new List<short>(dplcs.Count);
List<byte> mapbytes = new List<byte>();
for (int i = 0; i < dplcs.Length; i++)
for (int i = 0; i < dplcs.Count; i++)
if (i == 0 & dplcs[i].Count == 0 & version != EngineVersion.S3K & version != EngineVersion.SKC)
offs.Add(0);
else
Expand All @@ -1969,9 +1970,9 @@ public static byte[] GetBytes(DPLCFrame[] dplcs, EngineVersion version)
if (found) continue;
offs.Add((short)off);
mapbytes.AddRange(dplcs[i].GetBytes(version));
off = dplcs.Length * 2 + mapbytes.Count;
off = dplcs.Count * 2 + mapbytes.Count;
}
List<byte> result = new List<byte>(dplcs.Length * 2 + mapbytes.Count);
List<byte> result = new List<byte>(dplcs.Count * 2 + mapbytes.Count);
foreach (short item in offs)
result.AddRange(ByteConverter.GetBytes(item));
result.AddRange(mapbytes);
Expand Down

0 comments on commit 2e3a10b

Please sign in to comment.