2008-01-25 19:12:34 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2008-05-31 19:31:45 +00:00
|
|
|
using System.Windows.Forms;
|
2008-06-01 20:25:46 +00:00
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using CodeImp.DoomBuilder.Types;
|
2008-01-25 19:12:34 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.IO
|
|
|
|
{
|
|
|
|
internal class UniversalMapSetIO : MapSetIO
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2008-05-31 19:31:45 +00:00
|
|
|
// Name of the UDMF configuration file
|
|
|
|
private const string UDMF_CONFIG_NAME = "UDMF.cfg";
|
|
|
|
|
2008-01-25 19:12:34 +00:00
|
|
|
#endregion
|
|
|
|
|
2008-05-31 19:31:45 +00:00
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
private Configuration config;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-01-25 19:12:34 +00:00
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2008-05-31 19:31:45 +00:00
|
|
|
public UniversalMapSetIO(WAD wad, MapManager manager) : base(wad, manager)
|
2008-01-25 19:12:34 +00:00
|
|
|
{
|
2008-05-31 19:31:45 +00:00
|
|
|
// Make configuration
|
|
|
|
config = new Configuration();
|
2008-09-10 15:00:23 +00:00
|
|
|
|
|
|
|
// Find a resource named UDMF.cfg
|
2008-05-31 19:31:45 +00:00
|
|
|
string[] resnames = General.ThisAssembly.GetManifestResourceNames();
|
|
|
|
foreach(string rn in resnames)
|
|
|
|
{
|
|
|
|
// Found it?
|
|
|
|
if(rn.EndsWith(UDMF_CONFIG_NAME, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
// 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());
|
|
|
|
|
2008-06-01 20:25:46 +00:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Add thing flags
|
|
|
|
foreach(KeyValuePair<string, string> flag in General.Map.Config.ThingFlags)
|
|
|
|
config.WriteSetting("managedfields.thing." + flag.Key, true);
|
|
|
|
|
2008-05-31 19:31:45 +00:00
|
|
|
// Done
|
|
|
|
udmfcfgreader.Dispose();
|
|
|
|
udmfcfg.Dispose();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-01-25 19:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public override int MaxSidedefs { get { return int.MaxValue; } }
|
2009-04-08 19:11:40 +00:00
|
|
|
public override int MaxVertices { get { return int.MaxValue; } }
|
|
|
|
public override int MaxLinedefs { get { return int.MaxValue; } }
|
|
|
|
public override int MaxSectors { get { return int.MaxValue; } }
|
|
|
|
public override int MaxThings { get { return int.MaxValue; } }
|
|
|
|
public override int MinTextureOffset { get { return int.MinValue; } }
|
|
|
|
public override int MaxTextureOffset { get { return int.MaxValue; } }
|
2008-05-05 22:22:53 +00:00
|
|
|
public override int VertexDecimals { get { return 3; } }
|
2008-05-13 14:24:35 +00:00
|
|
|
public override string DecimalsFormat { get { return "0.000"; } }
|
2009-04-08 19:11:40 +00:00
|
|
|
public override bool HasLinedefTag { get { return true; } }
|
|
|
|
public override bool HasThingTag { get { return true; } }
|
|
|
|
public override bool HasThingAction { get { return true; } }
|
|
|
|
public override bool HasCustomFields { get { return true; } }
|
|
|
|
public override bool HasThingHeight { get { return true; } }
|
|
|
|
public override bool HasActionArgs { get { return true; } }
|
|
|
|
public override bool HasMixedActivations { get { return true; } }
|
|
|
|
public override bool HasPresetActivations { get { return false; } }
|
2009-04-08 20:49:35 +00:00
|
|
|
public override bool HasBuiltInActivations { get { return false; } }
|
2009-04-09 11:46:51 +00:00
|
|
|
public override int MaxTag { get { return int.MaxValue; } }
|
|
|
|
public override int MinTag { get { return int.MinValue; } }
|
|
|
|
public override int MaxAction { get { return int.MaxValue; } }
|
|
|
|
public override int MinAction { get { return int.MinValue; } }
|
|
|
|
public override int MaxEffect { get { return int.MaxValue; } }
|
|
|
|
public override int MinEffect { get { return int.MinValue; } }
|
|
|
|
public override int MaxBrightness { get { return int.MaxValue; } }
|
|
|
|
public override int MinBrightness { get { return int.MinValue; } }
|
|
|
|
public override int MaxThingType { get { return int.MaxValue; } }
|
|
|
|
public override int MinThingType { get { return int.MinValue; } }
|
2009-04-08 19:11:40 +00:00
|
|
|
public override double MaxCoordinate { get { return (double)float.MaxValue; } }
|
|
|
|
public override double MinCoordinate { get { return (double)float.MinValue; } }
|
|
|
|
|
2008-01-25 19:12:34 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Reading
|
2008-06-01 20:25:46 +00:00
|
|
|
|
2008-01-25 19:12:34 +00:00
|
|
|
// This reads a map from the file and returns a MapSet
|
|
|
|
public override MapSet Read(MapSet map, string mapname)
|
|
|
|
{
|
2008-09-17 19:21:45 +00:00
|
|
|
UniversalStreamReader udmfreader = new UniversalStreamReader();
|
2008-05-31 19:31:45 +00:00
|
|
|
|
|
|
|
// Find the index where first map lump begins
|
|
|
|
int firstindex = wad.FindLumpIndex(mapname) + 1;
|
|
|
|
|
|
|
|
// Get the TEXTMAP lump from wad file
|
|
|
|
Lump lump = wad.FindLump("TEXTMAP", firstindex);
|
|
|
|
if(lump == null) throw new Exception("Could not find required lump TEXTMAP!");
|
|
|
|
|
2008-09-17 19:21:45 +00:00
|
|
|
// Read the UDMF data
|
|
|
|
lump.Stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
udmfreader.SetKnownCustomTypes = true;
|
|
|
|
udmfreader.Read(map, lump.Stream);
|
2008-06-01 20:25:46 +00:00
|
|
|
|
|
|
|
// Return result
|
2008-09-17 19:21:45 +00:00
|
|
|
return map;
|
2008-06-01 20:25:46 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 19:12:34 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Writing
|
|
|
|
|
|
|
|
// This writes a MapSet to the file
|
|
|
|
public override void Write(MapSet map, string mapname, int position)
|
|
|
|
{
|
2008-09-17 19:21:45 +00:00
|
|
|
UniversalStreamWriter udmfwriter = new UniversalStreamWriter();
|
2008-06-01 20:25:46 +00:00
|
|
|
|
2008-09-17 19:21:45 +00:00
|
|
|
// Write map to memory stream
|
|
|
|
MemoryStream memstream = new MemoryStream();
|
|
|
|
memstream.Seek(0, SeekOrigin.Begin);
|
|
|
|
udmfwriter.RememberCustomTypes = true;
|
|
|
|
udmfwriter.Write(map, memstream, manager.Config.EngineName);
|
|
|
|
|
2008-06-01 20:25:46 +00:00
|
|
|
// Find insert position and remove old lump
|
2008-11-10 21:06:02 +00:00
|
|
|
int insertpos = MapManager.RemoveSpecificLump(wad, "TEXTMAP", position, MapManager.TEMP_MAP_HEADER, manager.Config.MapLumpNames);
|
2008-06-01 20:25:46 +00:00
|
|
|
if(insertpos == -1) insertpos = position + 1;
|
|
|
|
if(insertpos > wad.Lumps.Count) insertpos = wad.Lumps.Count;
|
2008-01-25 19:12:34 +00:00
|
|
|
|
2008-06-01 20:25:46 +00:00
|
|
|
// Create the lump from memory
|
2008-09-17 19:21:45 +00:00
|
|
|
Lump lump = wad.Insert("TEXTMAP", insertpos, (int)memstream.Length);
|
2008-06-01 20:25:46 +00:00
|
|
|
lump.Stream.Seek(0, SeekOrigin.Begin);
|
2008-09-17 19:21:45 +00:00
|
|
|
memstream.WriteTo(lump.Stream);
|
2008-06-01 20:25:46 +00:00
|
|
|
|
2008-09-17 19:21:45 +00:00
|
|
|
// Done
|
|
|
|
memstream.Dispose();
|
2008-06-01 20:25:46 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 19:12:34 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
2008-06-01 20:25:46 +00:00
|
|
|
|