2013-12-17 08:19:40 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
|
using CodeImp.DoomBuilder.Types;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.IO
|
|
|
|
|
{
|
|
|
|
|
internal class ClipboardStreamWriter
|
|
|
|
|
{
|
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
|
|
private const string UDMF_CONFIG_NAME = "UDMF.cfg";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
2016-02-22 08:20:33 +00:00
|
|
|
|
private readonly Configuration config;
|
2013-12-17 08:19:40 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public ClipboardStreamWriter()
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
// Make configurations
|
|
|
|
|
config = new Configuration();
|
|
|
|
|
|
|
|
|
|
// Find a resource named UDMF.cfg
|
|
|
|
|
string[] resnames = General.ThisAssembly.GetManifestResourceNames();
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(string rn in resnames)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
// Found it?
|
2016-02-01 22:04:00 +00:00
|
|
|
|
if(rn.EndsWith(UDMF_CONFIG_NAME, StringComparison.OrdinalIgnoreCase))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
// Get a stream from the resource
|
|
|
|
|
Stream udmfcfg = General.ThisAssembly.GetManifestResourceStream(rn);
|
|
|
|
|
StreamReader udmfcfgreader = new StreamReader(udmfcfg, Encoding.ASCII);
|
|
|
|
|
|
|
|
|
|
// Load configuration from stream
|
|
|
|
|
config.InputConfiguration(udmfcfgreader.ReadToEnd());
|
|
|
|
|
|
|
|
|
|
// Now we add the linedef flags, activations and thing flags
|
|
|
|
|
// to this list, so that these don't show up in the custom
|
|
|
|
|
// fields list either. We use true as dummy value (it has no meaning)
|
|
|
|
|
|
|
|
|
|
// Add linedef flags
|
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.LinedefFlags)
|
|
|
|
|
config.WriteSetting("managedfields.linedef." + flag.Key, true);
|
|
|
|
|
|
|
|
|
|
// Add linedef activations
|
|
|
|
|
foreach(LinedefActivateInfo activate in General.Map.Config.LinedefActivates)
|
|
|
|
|
config.WriteSetting("managedfields.linedef." + activate.Key, true);
|
|
|
|
|
|
|
|
|
|
//mxd. Add sidedef flags
|
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.SidedefFlags)
|
|
|
|
|
config.WriteSetting("managedfields.sidedef." + flag.Key, true);
|
|
|
|
|
|
|
|
|
|
//mxd. Add sector flags
|
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.SectorFlags)
|
|
|
|
|
config.WriteSetting("managedfields.sector." + flag.Key, true);
|
2016-10-11 12:58:35 +00:00
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.CeilingPortalFlags)
|
|
|
|
|
config.WriteSetting("managedfields.sector." + flag.Key, true);
|
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.FloorPortalFlags)
|
|
|
|
|
config.WriteSetting("managedfields.sector." + flag.Key, true);
|
2013-12-17 08:19:40 +00:00
|
|
|
|
|
|
|
|
|
// Add thing flags
|
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.ThingFlags)
|
|
|
|
|
config.WriteSetting("managedfields.thing." + flag.Key, true);
|
|
|
|
|
|
|
|
|
|
// Done
|
|
|
|
|
udmfcfgreader.Dispose();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Writing
|
|
|
|
|
|
2016-02-22 08:20:33 +00:00
|
|
|
|
public void Write(MapSet map, Stream stream)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-02-22 08:20:33 +00:00
|
|
|
|
Write(map.Vertices, map.Linedefs, map.Sidedefs, map.Sectors, map.Things, stream);
|
2013-12-17 08:19:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Write(ICollection<Vertex> vertices, ICollection<Linedef> linedefs, ICollection<Sidedef> sidedefs,
|
2016-02-22 08:20:33 +00:00
|
|
|
|
ICollection<Sector> sectors, ICollection<Thing> things, Stream stream)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
// Create collections
|
|
|
|
|
Dictionary<Vertex, int> vertexids = new Dictionary<Vertex, int>();
|
|
|
|
|
Dictionary<Sidedef, int> sidedefids = new Dictionary<Sidedef, int>();
|
|
|
|
|
Dictionary<Sector, int> sectorids = new Dictionary<Sector, int>();
|
|
|
|
|
|
|
|
|
|
// Index the elements in the data structures
|
|
|
|
|
foreach(Vertex v in vertices) vertexids.Add(v, vertexids.Count);
|
|
|
|
|
foreach(Sidedef sd in sidedefs) sidedefids.Add(sd, sidedefids.Count);
|
|
|
|
|
foreach(Sector s in sectors) sectorids.Add(s, sectorids.Count);
|
|
|
|
|
|
|
|
|
|
BinaryWriter writer = new BinaryWriter(stream);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
|
2013-12-17 08:19:40 +00:00
|
|
|
|
// Write the data structures to stream
|
2016-02-22 08:20:33 +00:00
|
|
|
|
writer.Write(vertices.Count); //mxd
|
|
|
|
|
writer.Write(sectors.Count); //mxd
|
|
|
|
|
writer.Write(linedefs.Count); //mxd
|
|
|
|
|
writer.Write(things.Count); //mxd
|
2013-12-17 08:19:40 +00:00
|
|
|
|
WriteVertices(vertices, writer);
|
|
|
|
|
WriteSectors(sectors, writer);
|
|
|
|
|
WriteSidedefs(sidedefs, writer, sectorids);
|
|
|
|
|
WriteLinedefs(linedefs, writer, sidedefids, vertexids);
|
|
|
|
|
WriteThings(things, writer);
|
|
|
|
|
writer.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void WriteVertices(ICollection<Vertex> vertices, BinaryWriter writer)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(vertices.Count);
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Vertex v in vertices)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
//write "static" properties
|
|
|
|
|
writer.Write(v.Position.x);
|
|
|
|
|
writer.Write(v.Position.y);
|
|
|
|
|
writer.Write(v.ZCeiling);
|
|
|
|
|
writer.Write(v.ZFloor);
|
|
|
|
|
|
|
|
|
|
// Write custom fields
|
|
|
|
|
AddCustomFields(v.Fields, "vertex", writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This adds linedefs
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void WriteLinedefs(ICollection<Linedef> linedefs, BinaryWriter writer, IDictionary<Sidedef, int> sidedefids, IDictionary<Vertex, int> vertexids)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(linedefs.Count);
|
|
|
|
|
|
|
|
|
|
// Go for all linedefs
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Linedef l in linedefs)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
//write "static" properties
|
|
|
|
|
writer.Write(vertexids[l.Start]);
|
|
|
|
|
writer.Write(vertexids[l.End]);
|
|
|
|
|
|
|
|
|
|
//sidedefs
|
|
|
|
|
writer.Write((l.Front != null && sidedefids.ContainsKey(l.Front)) ? sidedefids[l.Front] : -1);
|
|
|
|
|
writer.Write((l.Back != null && sidedefids.ContainsKey(l.Back)) ? sidedefids[l.Back] : -1);
|
|
|
|
|
|
|
|
|
|
//action and args
|
|
|
|
|
writer.Write(l.Action);
|
|
|
|
|
for(int i = 0; i < l.Args.Length; i++) writer.Write(l.Args[i]);
|
|
|
|
|
|
2015-07-27 21:35:42 +00:00
|
|
|
|
//mxd. Tags
|
|
|
|
|
writer.Write(l.Tags.Count);
|
|
|
|
|
for(int i = 0; i < l.Tags.Count; i++) writer.Write(l.Tags[i]);
|
|
|
|
|
|
2013-12-17 08:19:40 +00:00
|
|
|
|
AddFlags(l.Flags, writer);
|
|
|
|
|
AddCustomFields(l.Fields, "linedef", writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This adds sidedefs
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void WriteSidedefs(ICollection<Sidedef> sidedefs, BinaryWriter writer, IDictionary<Sector, int> sectorids)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(sidedefs.Count);
|
|
|
|
|
|
|
|
|
|
// Go for all sidedefs
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Sidedef s in sidedefs)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
//write "static" properties
|
|
|
|
|
writer.Write(s.OffsetX);
|
|
|
|
|
writer.Write(s.OffsetY);
|
|
|
|
|
writer.Write(sectorids[s.Sector]);
|
|
|
|
|
|
|
|
|
|
//textures
|
|
|
|
|
writer.Write(s.HighTexture.Length);
|
|
|
|
|
writer.Write(s.HighTexture.ToCharArray());
|
|
|
|
|
writer.Write(s.MiddleTexture.Length);
|
|
|
|
|
writer.Write(s.MiddleTexture.ToCharArray());
|
|
|
|
|
writer.Write(s.LowTexture.Length);
|
|
|
|
|
writer.Write(s.LowTexture.ToCharArray());
|
|
|
|
|
|
|
|
|
|
AddFlags(s.Flags, writer);
|
|
|
|
|
AddCustomFields(s.Fields, "sidedef", writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This adds sectors
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void WriteSectors(ICollection<Sector> sectors, BinaryWriter writer)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(sectors.Count);
|
|
|
|
|
|
|
|
|
|
// Go for all sectors
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Sector s in sectors)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
//write "static" properties
|
|
|
|
|
writer.Write(s.Effect);
|
|
|
|
|
writer.Write(s.FloorHeight);
|
|
|
|
|
writer.Write(s.CeilHeight);
|
|
|
|
|
writer.Write(s.Brightness);
|
|
|
|
|
|
2015-07-27 21:35:42 +00:00
|
|
|
|
//mxd. Tags
|
|
|
|
|
writer.Write(s.Tags.Count);
|
|
|
|
|
for(int i = 0; i < s.Tags.Count; i++) writer.Write(s.Tags[i]);
|
|
|
|
|
|
2013-12-17 08:19:40 +00:00
|
|
|
|
//textures
|
|
|
|
|
writer.Write(s.FloorTexture.Length);
|
|
|
|
|
writer.Write(s.FloorTexture.ToCharArray());
|
|
|
|
|
writer.Write(s.CeilTexture.Length);
|
|
|
|
|
writer.Write(s.CeilTexture.ToCharArray());
|
|
|
|
|
|
2014-08-25 11:15:19 +00:00
|
|
|
|
//mxd. Slopes
|
|
|
|
|
writer.Write(s.FloorSlopeOffset);
|
|
|
|
|
writer.Write(s.FloorSlope.x);
|
|
|
|
|
writer.Write(s.FloorSlope.y);
|
|
|
|
|
writer.Write(s.FloorSlope.z);
|
2014-10-17 11:55:08 +00:00
|
|
|
|
writer.Write(s.CeilSlopeOffset);
|
|
|
|
|
writer.Write(s.CeilSlope.x);
|
|
|
|
|
writer.Write(s.CeilSlope.y);
|
|
|
|
|
writer.Write(s.CeilSlope.z);
|
2014-08-25 11:15:19 +00:00
|
|
|
|
|
2013-12-17 08:19:40 +00:00
|
|
|
|
AddFlags(s.Flags, writer);
|
|
|
|
|
AddCustomFields(s.Fields, "sector", writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This adds things
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void WriteThings(ICollection<Thing> things, BinaryWriter writer)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(things.Count);
|
|
|
|
|
|
|
|
|
|
// Go for all things
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing t in things)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
//write "static" properties
|
|
|
|
|
writer.Write(t.Tag);
|
|
|
|
|
writer.Write(t.Position.x);
|
|
|
|
|
writer.Write(t.Position.y);
|
|
|
|
|
writer.Write(t.Position.z);
|
|
|
|
|
writer.Write(t.AngleDoom);
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
|
writer.Write(t.Pitch); //mxd
|
|
|
|
|
writer.Write(t.Roll); //mxd
|
|
|
|
|
writer.Write(t.ScaleX); //mxd
|
|
|
|
|
writer.Write(t.ScaleY); //mxd
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(t.Type);
|
|
|
|
|
writer.Write(t.Action);
|
|
|
|
|
for(int i = 0; i < t.Args.Length; i++) writer.Write(t.Args[i]);
|
|
|
|
|
|
|
|
|
|
AddFlags(t.Flags, writer);
|
|
|
|
|
AddCustomFields(t.Fields, "thing", writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void AddCustomFields(UniFields elementFields, string elementname, BinaryWriter writer)
|
|
|
|
|
{
|
2014-02-26 14:11:06 +00:00
|
|
|
|
Dictionary<string, UniValue> fields = new Dictionary<string, UniValue>(StringComparer.Ordinal);
|
2013-12-17 08:19:40 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(KeyValuePair<string, UniValue> f in elementFields)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
if(config.SettingExists("managedfields." + elementname + "." + f.Key)) continue;
|
|
|
|
|
fields.Add(f.Key, f.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writer.Write(fields.Count);
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(KeyValuePair<string, UniValue> f in fields)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(f.Key.Length);
|
|
|
|
|
writer.Write(f.Key.ToCharArray());
|
|
|
|
|
|
|
|
|
|
writer.Write(f.Value.Type);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(f.Value.Value is bool)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write((int)UniversalType.Boolean);
|
|
|
|
|
writer.Write((bool)f.Value.Value);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if(f.Value.Value is float)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write((int)UniversalType.Float);
|
|
|
|
|
writer.Write((float)f.Value.Value);
|
2020-05-22 19:39:18 +00:00
|
|
|
|
}
|
|
|
|
|
else if(f.Value.Value is double)
|
|
|
|
|
{
|
|
|
|
|
writer.Write((int)UniversalType.Float);
|
|
|
|
|
writer.Write((double)f.Value.Value);
|
|
|
|
|
}
|
2014-12-03 23:15:26 +00:00
|
|
|
|
else if(f.Value.Value.GetType().IsPrimitive)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write((int)UniversalType.Integer);
|
|
|
|
|
writer.Write((int)f.Value.Value);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if(f.Value.Value is string)
|
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write((int)UniversalType.String);
|
|
|
|
|
string s = (string)f.Value.Value;
|
|
|
|
|
writer.Write(s.Length);
|
|
|
|
|
writer.Write(s.ToCharArray());
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else //WOLOLO! ERRORS!
|
2016-02-22 08:20:33 +00:00
|
|
|
|
{
|
|
|
|
|
General.ErrorLogger.Add(ErrorType.Error, "Unable to copy Universal Field \"" + f.Key + "\" to clipboard: unknown value type \"" + f.Value.Type + "\"!");
|
2013-12-17 08:19:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 18:20:47 +00:00
|
|
|
|
private static void AddFlags(Dictionary<string, bool> flags, BinaryWriter writer)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-12-17 08:19:40 +00:00
|
|
|
|
writer.Write(flags.Count);
|
|
|
|
|
|
2016-01-15 18:20:47 +00:00
|
|
|
|
foreach(KeyValuePair<string, bool> group in flags)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-01-15 18:20:47 +00:00
|
|
|
|
writer.Write(group.Key.Length);
|
|
|
|
|
writer.Write(group.Key.ToCharArray());
|
|
|
|
|
writer.Write(group.Value);
|
2013-12-17 08:19:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|