Commented and tabified

This commit is contained in:
Michael Becker 2014-09-15 08:52:19 -04:00
parent 99db1b6dd9
commit 8176608b31
9 changed files with 242 additions and 201 deletions

View File

@ -5,22 +5,27 @@ using System.Text;
namespace UniversalEditor.Collections.Generic
{
public class AutoDictionary<TKey, TValue> : System.Collections.Generic.Dictionary<TKey, TValue>
/// <summary>
/// Provides a <see cref="Dictionary" /> that automatically adds or updates a key or value when it is
/// requested.
/// </summary>
/// <typeparam name="TKey">The type of the key part of the dictionary.</typeparam>
/// <typeparam name="TValue">The type of the value part of the dictionary.</typeparam>
public class AutoDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{
public new TValue this[TKey key]
{
get
{
return this[key, default(TValue)];
}
get { return this[key, default(TValue)]; }
set
{
if (ContainsKey(key))
{
// we already contain an item with this key, so update the value accordingly
base[key] = value;
}
else
{
// we do not already contain an item with this key, so create a new value
base.Add(key, value);
}
}
@ -31,18 +36,18 @@ namespace UniversalEditor.Collections.Generic
{
if (ContainsKey(key))
{
// we already contain an item with this key, so return the value accordingly
return base[key];
}
else
{
// we do not already contain an item with this key, so create a new value set to the
// specified default value and return that
base.Add(key, defaultValue);
return defaultValue;
}
}
set
{
this[key] = value;
}
set { this[key] = value; }
}
}
}

View File

@ -4,10 +4,16 @@ using System.Text;
namespace UniversalEditor.Collections.Generic
{
/// <summary>
/// Provides a collection that can be keyed either forward (T1=>T2) or backward (T2=>T1).
/// </summary>
/// <typeparam name="T1">The type of the value on which to forward-key the collection.</typeparam>
/// <typeparam name="T2">The type of the value on which to backward-key the collection.</typeparam>
public class BidirectionalDictionary<T1, T2> : System.Collections.IEnumerable
{
private Dictionary<T1, T2> mvarForwardDictionary = new Dictionary<T1, T2>();
private Dictionary<T2, T1> mvarBackwardDictionary = new Dictionary<T2, T1>();
public void Add(T1 value1, T2 value2)
{
this.mvarForwardDictionary.Add(value1, value2);
@ -50,22 +56,22 @@ namespace UniversalEditor.Collections.Generic
return this.mvarForwardDictionary.GetEnumerator();
}
public bool ContainsValue1(T1 value)
{
return this.mvarForwardDictionary.ContainsKey(value);
}
public bool ContainsValue2(T2 value)
{
return this.mvarBackwardDictionary.ContainsKey(value);
}
public bool ContainsValue1(T1 value)
{
return this.mvarForwardDictionary.ContainsKey(value);
}
public bool ContainsValue2(T2 value)
{
return this.mvarBackwardDictionary.ContainsKey(value);
}
public int Count
{
get
{
if (mvarForwardDictionary.Count != mvarBackwardDictionary.Count) throw new InvalidOperationException("Count mismatch");
return mvarBackwardDictionary.Count;
}
}
public int Count
{
get
{
if (mvarForwardDictionary.Count != mvarBackwardDictionary.Count) throw new InvalidOperationException("Count mismatch");
return mvarBackwardDictionary.Count;
}
}
}
}

View File

@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\..\Output\Debug\Plugins\UniversalEditor.Essential.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -6,50 +6,53 @@ using UniversalEditor.ObjectModels.FileSystem;
namespace UniversalEditor.DataFormats.AniMiku.AnimatedTexture
{
public class AMTDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("AniMiku texture package", new string[] { "*.amt" });
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) return;
/// <summary>
/// Implements the AniMiku Texture Package data format.
/// </summary>
public class AMTDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("AniMiku texture package", new string[] { "*.amt" });
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) return;
IO.Reader br = base.Accessor.Reader;
int unknown = br.ReadInt32();
int count = br.ReadInt32();
for (int i = 0; i < count; i++)
{
int dataSize = br.ReadInt32();
byte[] data = br.ReadBytes(dataSize);
fsom.Files.Add(i.ToString().PadLeft(8, '0'), data);
}
}
protected override void SaveInternal(ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) return;
IO.Reader br = base.Accessor.Reader;
int unknown = br.ReadInt32();
int count = br.ReadInt32();
for (int i = 0; i < count; i++)
{
int dataSize = br.ReadInt32();
byte[] data = br.ReadBytes(dataSize);
fsom.Files.Add(i.ToString().PadLeft(8, '0'), data);
}
}
protected override void SaveInternal(ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) return;
IO.Writer bw = base.Accessor.Writer;
int unknown = 150;
bw.WriteInt32(unknown);
IO.Writer bw = base.Accessor.Writer;
int unknown = 150;
bw.WriteInt32(unknown);
bw.WriteInt32(fsom.Files.Count);
foreach (File file in fsom.Files)
{
byte[] data = file.GetDataAsByteArray();
bw.WriteInt32(data.Length);
bw.WriteBytes(data);
}
}
}
bw.WriteInt32(fsom.Files.Count);
foreach (File file in fsom.Files)
{
byte[] data = file.GetDataAsByteArray();
bw.WriteInt32(data.Length);
bw.WriteBytes(data);
}
}
}
}

View File

@ -13,6 +13,9 @@ using UniversalEditor.ObjectModels.Concertroid.Concert;
namespace UniversalEditor.DataFormats.AniMiku.Concert
{
/// <summary>
/// Implements the AniMiku performance data format.
/// </summary>
public class AniMikuINIDataFormat : WindowsConfigurationDataFormat
{
public override DataFormatReference MakeReference()
@ -54,17 +57,25 @@ namespace UniversalEditor.DataFormats.AniMiku.Concert
Performance perf = new Performance();
// The title of the song used in this performance.
Property prpName = grp.Properties["name"];
perf.Title = prpName.Value.ToString();
// File name of the motion data files associated with characters 1 and 2.
Property prpVmd1 = grp.Properties["vmd1"];
Property prpVmd2 = grp.Properties["vmd2"];
// Background audio to play during the performance, and delay in milliseconds between
// start of animation and start of audio.
Property prpSound = grp.Properties["sound"];
Property prpDelay = grp.Properties["delay"];
// File name of the model data files associated with characters 1 and 2.
Property prpModel1 = grp.Properties["model1"];
Property prpModel2 = grp.Properties["model2"];
// Offset of the model along the X axis. Currently AMP does not support offsetting the
// model along the Y axis.
Property prpOffset1 = grp.Properties["offset1"];
Property prpOffset2 = grp.Properties["offset2"];

View File

@ -13,45 +13,49 @@ using UniversalEditor.ObjectModels.Multimedia3D.Model;
namespace UniversalEditor.DataFormats.AniMiku.ExtendedPMD
{
public class ExtendedPMDDataFormat : PMDModelDataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Clear();
_dfr.Capabilities.Add(typeof(ModelObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("AniMiku extended Polygon Movie Maker model", new string[] { "*.apmd" });
_dfr.Priority = 1;
}
return _dfr;
}
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
{
base.AfterLoadInternal(objectModels);
/// <summary>
/// Implements the AniMiku extended PMD (APMD) data format. This is different than the PMAX (PMD by
/// ALCEproject Extended) data format implemented by Concertroid.
/// </summary>
public class ExtendedPMDDataFormat : PMDModelDataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Clear();
_dfr.Capabilities.Add(typeof(ModelObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("AniMiku extended Polygon Movie Maker model", new string[] { "*.apmd" });
_dfr.Priority = 1;
}
return _dfr;
}
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
{
base.AfterLoadInternal(objectModels);
ModelObjectModel model = (objectModels.Pop() as ModelObjectModel);
ModelObjectModel model = (objectModels.Pop() as ModelObjectModel);
// attempt to load more
IO.Reader br = base.Accessor.Reader;
if (br.EndOfStream) return;
byte[] datas = br.ReadUntil("END", false);
// attempt to load more
IO.Reader br = base.Accessor.Reader;
if (br.EndOfStream) return;
byte[] datas = br.ReadUntil("END", false);
PMDExtensionObjectModel pmdo = new PMDExtensionObjectModel();
PMDExtensionDataFormat pmdf = new PMDExtensionDataFormat();
pmdf.Model = model;
Document.Load(pmdo, pmdf, new MemoryAccessor(datas), true);
foreach (PMDExtensionTextureGroup file in pmdo.ArchiveFiles)
{
foreach (string fileName in file.TextureImageFileNames)
{
file.Material.Textures.Add(file.ArchiveFileName + "::/" + fileName, null, ModelTextureFlags.Texture);
}
}
}
}
PMDExtensionObjectModel pmdo = new PMDExtensionObjectModel();
PMDExtensionDataFormat pmdf = new PMDExtensionDataFormat();
pmdf.Model = model;
Document.Load(pmdo, pmdf, new MemoryAccessor(datas), true);
foreach (PMDExtensionTextureGroup file in pmdo.ArchiveFiles)
{
foreach (string fileName in file.TextureImageFileNames)
{
file.Material.Textures.Add(file.ArchiveFileName + "::/" + fileName, null, ModelTextureFlags.Texture);
}
}
}
}
}

View File

@ -8,86 +8,90 @@ using UniversalEditor.ObjectModels.Multimedia3D.Model;
namespace UniversalEditor.DataFormats.AniMiku.PMDExtension
{
internal class PMDExtensionDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(PMDExtensionObjectModel), DataFormatCapabilities.All);
// _dfr.Filters.Add("AniMiku PMD extension");
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
PMDExtensionObjectModel pmdo = (objectModel as PMDExtensionObjectModel);
if (pmdo == null) return;
/// <summary>
/// Implements an internal <see cref="DataFormat" /> for processing PMAX extensions to the PMD data
/// format.
/// </summary>
internal class PMDExtensionDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(PMDExtensionObjectModel), DataFormatCapabilities.All);
// _dfr.Filters.Add("AniMiku PMD extension");
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
PMDExtensionObjectModel pmdo = (objectModel as PMDExtensionObjectModel);
if (pmdo == null) return;
IO.Reader br = base.Accessor.Reader;
foreach (ModelMaterial mat in mvarModel.Materials)
{
mat.AlwaysLight = br.ReadBoolean();
mat.EnableAnimation = br.ReadBoolean();
mat.EnableGlow = br.ReadBoolean();
IO.Reader br = base.Accessor.Reader;
foreach (ModelMaterial mat in mvarModel.Materials)
{
mat.AlwaysLight = br.ReadBoolean();
mat.EnableAnimation = br.ReadBoolean();
mat.EnableGlow = br.ReadBoolean();
if (mat.EnableAnimation)
{
int textureCount = br.ReadInt32();
string archiveFileName = br.ReadNullTerminatedString(100);
{
int textureCount = br.ReadInt32();
string archiveFileName = br.ReadNullTerminatedString(100);
PMDExtensionTextureGroup file = new PMDExtensionTextureGroup();
file.Material = mat;
file.ArchiveFileName = archiveFileName;
for (int i = 0; i < textureCount; i++)
{
string textureFileName = br.ReadNullTerminatedString(256);
file.TextureImageFileNames.Add(textureFileName);
}
pmdo.ArchiveFiles.Add(file);
}
}
PMDExtensionTextureGroup file = new PMDExtensionTextureGroup();
file.Material = mat;
file.ArchiveFileName = archiveFileName;
for (int i = 0; i < textureCount; i++)
{
string textureFileName = br.ReadNullTerminatedString(256);
file.TextureImageFileNames.Add(textureFileName);
}
pmdo.ArchiveFiles.Add(file);
}
}
int originalModelLength = br.ReadInt32();
string END = br.ReadFixedLengthString(3);
}
protected override void SaveInternal(ObjectModel objectModel)
{
int originalModelLength = br.ReadInt32();
string END = br.ReadFixedLengthString(3);
}
protected override void SaveInternal(ObjectModel objectModel)
{
#if READYTOSAVE
IO.Writer bw = base.Accessor.Writer;
foreach (ModelMaterial mat in mvarModel.Materials)
{
bw.Write(mat.AlwaysLight);
bw.Write(mat.EnableAnimation);
bw.Write(mat.EnableGlow);
IO.Writer bw = base.Accessor.Writer;
foreach (ModelMaterial mat in mvarModel.Materials)
{
bw.Write(mat.AlwaysLight);
bw.Write(mat.EnableAnimation);
bw.Write(mat.EnableGlow);
if (mat.EnableAnimation)
{
// TODO: figure out how to get texture count for the model
int textureCount = br.ReadInt32();
string archiveFileName = br.ReadNullTerminatedString(100);
if (mat.EnableAnimation)
{
// TODO: figure out how to get texture count for the model
int textureCount = br.ReadInt32();
string archiveFileName = br.ReadNullTerminatedString(100);
PMDExtensionTextureGroup file = new PMDExtensionTextureGroup();
file.Material = mat;
file.ArchiveFileName = archiveFileName;
for (int i = 0; i < textureCount; i++)
{
string textureFileName = br.ReadNullTerminatedString(256);
file.TextureImageFileNames.Add(textureFileName);
}
pmdo.ArchiveFiles.Add(file);
}
}
PMDExtensionTextureGroup file = new PMDExtensionTextureGroup();
file.Material = mat;
file.ArchiveFileName = archiveFileName;
for (int i = 0; i < textureCount; i++)
{
string textureFileName = br.ReadNullTerminatedString(256);
file.TextureImageFileNames.Add(textureFileName);
}
pmdo.ArchiveFiles.Add(file);
}
}
int originalModelLength = br.ReadInt32();
string END = br.ReadFixedLengthString(3);
int originalModelLength = br.ReadInt32();
string END = br.ReadFixedLengthString(3);
#endif
throw new NotImplementedException();
}
throw new NotImplementedException();
}
private ModelObjectModel mvarModel = null;
public ModelObjectModel Model { get { return mvarModel; } set { mvarModel = value; } }
}
private ModelObjectModel mvarModel = null;
public ModelObjectModel Model { get { return mvarModel; } set { mvarModel = value; } }
}
}

View File

@ -7,31 +7,37 @@ using UniversalEditor.ObjectModels.Multimedia3D.Model;
namespace UniversalEditor.ObjectModels.AniMiku.PMDExtension
{
public class PMDExtensionTextureGroup : ICloneable
{
public class PMDExtensionArchiveFileCollection
: System.Collections.ObjectModel.Collection<PMDExtensionTextureGroup>
{
}
public class PMDExtensionTextureGroup : ICloneable
{
public class PMDExtensionArchiveFileCollection
: System.Collections.ObjectModel.Collection<PMDExtensionTextureGroup>
{
}
private string mvarName = String.Empty;
public string ArchiveFileName { get { return mvarName; } set { mvarName = value; } }
private string mvarName = String.Empty;
/// <summary>
/// The name of the archive file associated with this PMD extension.
/// </summary>
public string ArchiveFileName { get { return mvarName; } set { mvarName = value; } }
private System.Collections.Specialized.StringCollection mvarTextureImageFileNames = new System.Collections.Specialized.StringCollection();
public System.Collections.Specialized.StringCollection TextureImageFileNames { get { return mvarTextureImageFileNames; } }
private System.Collections.Specialized.StringCollection mvarTextureImageFileNames = new System.Collections.Specialized.StringCollection();
/// <summary>
/// The file name(s) of texture(s) associated with this PMD extension.
/// </summary>
public System.Collections.Specialized.StringCollection TextureImageFileNames { get { return mvarTextureImageFileNames; } }
public object Clone()
{
PMDExtensionTextureGroup clone = new PMDExtensionTextureGroup();
clone.ArchiveFileName = (mvarName.Clone() as string);
foreach (string s in mvarTextureImageFileNames)
{
clone.TextureImageFileNames.Add(s.Clone() as string);
}
return clone;
}
public object Clone()
{
PMDExtensionTextureGroup clone = new PMDExtensionTextureGroup();
clone.ArchiveFileName = (mvarName.Clone() as string);
foreach (string s in mvarTextureImageFileNames)
{
clone.TextureImageFileNames.Add(s.Clone() as string);
}
return clone;
}
private ModelMaterial mvarMaterial = null;
public ModelMaterial Material { get { return mvarMaterial; } set { mvarMaterial = value; } }
}
private ModelMaterial mvarMaterial = null;
public ModelMaterial Material { get { return mvarMaterial; } set { mvarMaterial = value; } }
}
}

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\..\Output\Debug\Plugins\UniversalEditor.Plugins.AniMiku.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>