mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-23 12:22:35 +00:00
@working on decorate support
This commit is contained in:
parent
d2265287b4
commit
1694d828d1
17 changed files with 164 additions and 58 deletions
|
@ -67,7 +67,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
// Go for all the things
|
||||
foreach(Thing t in General.Map.Map.Things)
|
||||
{
|
||||
ThingTypeInfo info = General.Map.Config.GetThingInfo(t.Type);
|
||||
ThingTypeInfo info = General.Map.Data.GetThingInfo(t.Type);
|
||||
bool stucked = false;
|
||||
|
||||
// Check this thing for getting stucked?
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
// This must return the string that is displayed in the listbox
|
||||
public override string ToString()
|
||||
{
|
||||
return General.Map.Config.GetThingInfo(thing.Type).Title + " is stucked in a wall at " + thing.Position.x + ", " + thing.Position.y;
|
||||
return General.Map.Data.GetThingInfo(thing.Type).Title + " is stucked in a wall at " + thing.Position.x + ", " + thing.Position.y;
|
||||
}
|
||||
|
||||
// Rendering
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
// This must return the string that is displayed in the listbox
|
||||
public override string ToString()
|
||||
{
|
||||
return General.Map.Config.GetThingInfo(thing.Type).Title + " is outside the map at " + thing.Position.x + ", " + thing.Position.y;
|
||||
return General.Map.Data.GetThingInfo(thing.Type).Title + " is outside the map at " + thing.Position.x + ", " + thing.Position.y;
|
||||
}
|
||||
|
||||
// Rendering
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
public void Rebuild()
|
||||
{
|
||||
// Find thing information
|
||||
info = General.Map.Config.GetThingInfo(Thing.Type);
|
||||
info = General.Map.Data.GetThingInfo(Thing.Type);
|
||||
|
||||
// Find sprite texture
|
||||
if(info.Sprite.Length > 0)
|
||||
|
|
|
@ -158,8 +158,6 @@ namespace CodeImp.DoomBuilder.Config
|
|||
// Things
|
||||
public ICollection<string> DefaultThingFlags { get { return defaultthingflags; } }
|
||||
public IDictionary<string, string> ThingFlags { get { return thingflags; } }
|
||||
public List<ThingCategory> ThingCategories { get { return thingcategories; } }
|
||||
public ICollection<ThingTypeInfo> Things { get { return things.Values; } }
|
||||
public List<FlagTranslation> ThingFlagsTranslation { get { return thingflagstranslation; } }
|
||||
|
||||
// Linedefs
|
||||
|
@ -683,37 +681,16 @@ namespace CodeImp.DoomBuilder.Config
|
|||
public byte ReadSetting(string setting, byte defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
||||
public IDictionary ReadSetting(string setting, IDictionary defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
|
||||
|
||||
// This gets thing information by index
|
||||
public ThingTypeInfo GetThingInfo(int thingtype)
|
||||
// This gets a list of things categories
|
||||
internal List<ThingCategory> GetThingCategories()
|
||||
{
|
||||
// Index in config?
|
||||
if(things.ContainsKey(thingtype))
|
||||
{
|
||||
// Return from config
|
||||
return things[thingtype];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create unknown thing info
|
||||
return new ThingTypeInfo(thingtype);
|
||||
}
|
||||
return new List<ThingCategory>(thingcategories);
|
||||
}
|
||||
|
||||
// This gets thing information by index
|
||||
// Returns null when thing type info could not be found
|
||||
public ThingTypeInfo GetThingInfoEx(int thingtype)
|
||||
// This gets a list of things
|
||||
internal Dictionary<int, ThingTypeInfo> GetThingTypes()
|
||||
{
|
||||
// Index in config?
|
||||
if(things.ContainsKey(thingtype))
|
||||
{
|
||||
// Return from config
|
||||
return things[thingtype];
|
||||
}
|
||||
else
|
||||
{
|
||||
// No such thing type known
|
||||
return null;
|
||||
}
|
||||
return new Dictionary<int, ThingTypeInfo>(things);
|
||||
}
|
||||
|
||||
// This checks if an action is generalized or predefined
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
spritepanel.Left = infopanel.Left + infopanel.Width + infopanel.Margin.Right + spritepanel.Margin.Left;
|
||||
|
||||
// Lookup thing info
|
||||
ti = General.Map.Config.GetThingInfo(t.Type);
|
||||
ti = General.Map.Data.GetThingInfo(t.Type);
|
||||
|
||||
// Get thing action information
|
||||
if(General.Map.Config.LinedefActions.ContainsKey(t.Action))
|
||||
|
|
|
@ -31,6 +31,7 @@ using CodeImp.DoomBuilder.Config;
|
|||
using System.Threading;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using CodeImp.DoomBuilder.Windows;
|
||||
using CodeImp.DoomBuilder.Decorate;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -81,6 +82,10 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Used images
|
||||
private Dictionary<long, long> usedimages;
|
||||
|
||||
// Things combined with things created from Decorate
|
||||
private List<ThingCategory> thingcategories;
|
||||
private Dictionary<int, ThingTypeInfo> thingtypes;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
||||
|
@ -100,6 +105,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
public ImageData Crosshair3D { get { return crosshair; } }
|
||||
public ImageData CrosshairBusy3D { get { return crosshairbusy; } }
|
||||
public ImageData ThingBox { get { return thingbox; } }
|
||||
public List<ThingCategory> ThingCategories { get { return thingcategories; } }
|
||||
public ICollection<ThingTypeInfo> ThingTypes { get { return thingtypes.Values; } }
|
||||
internal ICollection<MatchingTextureSet> TextureSets { get { return texturesets; } }
|
||||
internal OthersTextureSet OthersTextureSet { get { return othertextures; } }
|
||||
internal AllTextureSet AllTextureSet { get { return alltextures; } }
|
||||
|
@ -188,7 +195,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// This loads all data resources
|
||||
internal void Load(DataLocationList locations)
|
||||
{
|
||||
int texcount, flatcount, spritecount;
|
||||
int texcount, flatcount, spritecount, thingcount;
|
||||
DataReader c;
|
||||
|
||||
// Create collections
|
||||
|
@ -203,6 +210,8 @@ namespace CodeImp.DoomBuilder.Data
|
|||
texturesets = new List<MatchingTextureSet>();
|
||||
usedimages = new Dictionary<long, long>();
|
||||
internalsprites = new Dictionary<string, ImageData>();
|
||||
thingcategories = General.Map.Config.GetThingCategories();
|
||||
thingtypes = General.Map.Config.GetThingTypes();
|
||||
|
||||
// Load texture sets
|
||||
foreach(DefinedTextureSet ts in General.Map.ConfigSettings.TextureSets)
|
||||
|
@ -263,6 +272,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
LoadPalette();
|
||||
texcount = LoadTextures();
|
||||
flatcount = LoadFlats();
|
||||
thingcount = LoadDecorateThings();
|
||||
spritecount = LoadSprites();
|
||||
LoadInternalSprites();
|
||||
|
||||
|
@ -307,7 +317,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
StartBackgroundLoader();
|
||||
|
||||
// Output info
|
||||
General.WriteLogLine("Loaded " + texcount + " textures, " + flatcount + " flats, " + spritecount + " sprites");
|
||||
General.WriteLogLine("Loaded " + texcount + " textures, " + flatcount + " flats, " + spritecount + " sprites, " + thingcount + " decorate things");
|
||||
}
|
||||
|
||||
// This unloads all data
|
||||
|
@ -862,7 +872,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
private int LoadSprites()
|
||||
{
|
||||
// Go for all things
|
||||
foreach(ThingTypeInfo ti in General.Map.Config.Things)
|
||||
foreach(ThingTypeInfo ti in General.Map.Data.ThingTypes)
|
||||
{
|
||||
// Sprite not added to collection yet?
|
||||
if(!sprites.ContainsKey(ti.SpriteLongName) && (ti.Sprite.Length <= 8))
|
||||
|
@ -1017,6 +1027,93 @@ namespace CodeImp.DoomBuilder.Data
|
|||
|
||||
#endregion
|
||||
|
||||
#region ================== Things
|
||||
|
||||
// This loads the things from Decorate
|
||||
private int LoadDecorateThings()
|
||||
{
|
||||
DecorateParser parser;
|
||||
int counter = 0;
|
||||
|
||||
// Create the parser
|
||||
parser = new DecorateParser();
|
||||
parser.OnInclude = LoadDecorateFromLocation;
|
||||
|
||||
// Go for all opened containers
|
||||
foreach(DataReader dr in containers)
|
||||
{
|
||||
// Load Decorate info cumulatively (the last Decorate is added to the previous)
|
||||
// I'm not sure if this is the right thing to do though.
|
||||
Stream decodata = dr.GetDecorateData("DECORATE");
|
||||
if(decodata != null)
|
||||
{
|
||||
// Parse the data
|
||||
decodata.Seek(0, SeekOrigin.Begin);
|
||||
parser.Parse(decodata);
|
||||
|
||||
// Check for errors
|
||||
if(parser.HasError)
|
||||
{
|
||||
General.WriteLogLine("ERROR: Unable to parse DECORATE data from location " + dr.Location.location + "!");
|
||||
General.WriteLogLine(parser.ErrorDescription + " on line " + parser.ErrorLine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!parser.HasError)
|
||||
{
|
||||
// Go for all actors in the decorate
|
||||
// TODO
|
||||
counter = parser.Actors.Count;
|
||||
}
|
||||
|
||||
// Output info
|
||||
return counter;
|
||||
}
|
||||
|
||||
// This loads Decorate data from a specific file or lump name
|
||||
private void LoadDecorateFromLocation(string location)
|
||||
{
|
||||
// TODO
|
||||
int t = 5;
|
||||
}
|
||||
|
||||
// This gets thing information by index
|
||||
public ThingTypeInfo GetThingInfo(int thingtype)
|
||||
{
|
||||
// Index in config?
|
||||
if(thingtypes.ContainsKey(thingtype))
|
||||
{
|
||||
// Return from config
|
||||
return thingtypes[thingtype];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create unknown thing info
|
||||
return new ThingTypeInfo(thingtype);
|
||||
}
|
||||
}
|
||||
|
||||
// This gets thing information by index
|
||||
// Returns null when thing type info could not be found
|
||||
public ThingTypeInfo GetThingInfoEx(int thingtype)
|
||||
{
|
||||
// Index in config?
|
||||
if(thingtypes.ContainsKey(thingtype))
|
||||
{
|
||||
// Return from config
|
||||
return thingtypes[thingtype];
|
||||
}
|
||||
else
|
||||
{
|
||||
// No such thing type known
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Tools
|
||||
|
||||
// This finds the first IWAD resource
|
||||
|
|
|
@ -33,6 +33,14 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
{
|
||||
public sealed class DecorateParser
|
||||
{
|
||||
#region ================== Delegates
|
||||
|
||||
public delegate void IncludeDelegate(string includefile);
|
||||
|
||||
public IncludeDelegate OnInclude;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constants
|
||||
|
||||
// Parsing
|
||||
|
@ -85,8 +93,10 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
// Returns false on errors
|
||||
public bool Parse(Stream stream)
|
||||
{
|
||||
datastream = stream;
|
||||
datareader = new StreamReader(datastream, Encoding.ASCII);
|
||||
Stream localstream = stream;
|
||||
StreamReader localreader = new StreamReader(localstream, Encoding.ASCII);
|
||||
datastream = localstream;
|
||||
datareader = localreader;
|
||||
datastream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Continue until at the end of the stream
|
||||
|
@ -103,6 +113,24 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
ActorStructure actor = new ActorStructure(this);
|
||||
if(this.HasError) break;
|
||||
}
|
||||
else if(objdeclaration == "#include")
|
||||
{
|
||||
// Include a file
|
||||
SkipWhitespace(true);
|
||||
string filename = ReadToken();
|
||||
if(!string.IsNullOrEmpty(filename))
|
||||
{
|
||||
if(OnInclude != null) OnInclude(filename);
|
||||
datastream = localstream;
|
||||
datareader = localreader;
|
||||
if(HasError) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportError("Expected file name to include");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown structure!
|
||||
|
@ -143,14 +171,15 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
internal bool SkipWhitespace(bool skipnewline)
|
||||
{
|
||||
int offset = skipnewline ? 1 : 0;
|
||||
char[] cb = new char[1];
|
||||
int c;
|
||||
|
||||
do
|
||||
{
|
||||
c = datareader.Read();
|
||||
c = datareader.Read(cb, 0, 1);
|
||||
if(c == -1) return false;
|
||||
}
|
||||
while(WHITESPACE.IndexOf(unchecked((char)c), offset) > -1);
|
||||
while(WHITESPACE.IndexOf(unchecked(cb[0]), offset) > -1);
|
||||
|
||||
// Go one character back so we can read this non-whitespace character again
|
||||
datastream.Seek(-1, SeekOrigin.Current);
|
||||
|
@ -162,6 +191,7 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
internal string ReadToken()
|
||||
{
|
||||
string token = "";
|
||||
bool quotedstring = false;
|
||||
int c;
|
||||
|
||||
// Return null when the end of the stream has been reached
|
||||
|
@ -169,12 +199,12 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
|
||||
// Start reading
|
||||
c = datareader.Read();
|
||||
while((c != -1) && !IsWhitespace(unchecked((char)c)))
|
||||
while((c != -1) && (!IsWhitespace(unchecked((char)c)) || quotedstring))
|
||||
{
|
||||
char cc = unchecked((char)c);
|
||||
|
||||
// Special token?
|
||||
if(IsSpecialToken(cc))
|
||||
if(!quotedstring && IsSpecialToken(cc))
|
||||
{
|
||||
// Not reading a token yet?
|
||||
if(token.Length == 0)
|
||||
|
@ -193,6 +223,12 @@ namespace CodeImp.DoomBuilder.Decorate
|
|||
}
|
||||
else
|
||||
{
|
||||
// Quote to end the string?
|
||||
if(quotedstring && (cc == '"')) quotedstring = false;
|
||||
|
||||
// First character is a quote?
|
||||
if((token.Length == 0) && (cc == '"')) quotedstring = true;
|
||||
|
||||
token += cc;
|
||||
}
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
bool qualifies;
|
||||
|
||||
// Get thing info
|
||||
ThingTypeInfo ti = General.Map.Config.GetThingInfo(t.Type);
|
||||
ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
|
||||
|
||||
// Check if thing is in unknown category
|
||||
if(ti.Category == null)
|
||||
|
|
|
@ -266,6 +266,7 @@ namespace CodeImp.DoomBuilder
|
|||
data.Load(configinfo.Resources, options.Resources);
|
||||
|
||||
// Update structures
|
||||
map.UpdateConfiguration();
|
||||
map.Update();
|
||||
thingsfilter.Update();
|
||||
|
||||
|
@ -355,6 +356,7 @@ namespace CodeImp.DoomBuilder
|
|||
data.Load(configinfo.Resources, options.Resources, maplocation);
|
||||
|
||||
// Update structures
|
||||
map.UpdateConfiguration();
|
||||
map.SnapAllToAccuracy();
|
||||
map.Update();
|
||||
thingsfilter.Update();
|
||||
|
|
|
@ -122,8 +122,6 @@ namespace CodeImp.DoomBuilder.IO
|
|||
// Create new item
|
||||
t = map.CreateThing();
|
||||
t.Update(type, x, y, 0, angle, stringflags, 0, 0, new int[Thing.NUM_ARGS]);
|
||||
//t.DetermineSector();
|
||||
t.UpdateConfiguration();
|
||||
}
|
||||
|
||||
// Done
|
||||
|
|
|
@ -132,8 +132,6 @@ namespace CodeImp.DoomBuilder.IO
|
|||
// Create new item
|
||||
t = map.CreateThing();
|
||||
t.Update(type, x, y, z, angle, stringflags, tag, action, args);
|
||||
//t.DetermineSector();
|
||||
t.UpdateConfiguration();
|
||||
}
|
||||
|
||||
// Done
|
||||
|
|
|
@ -181,8 +181,6 @@ namespace CodeImp.DoomBuilder.IO
|
|||
// Create new item
|
||||
Thing t = map.CreateThing();
|
||||
t.Update(type, x, y, height, Angle2D.DoomToReal(angledeg), stringflags, tag, special, args);
|
||||
//t.DetermineSector();
|
||||
t.UpdateConfiguration();
|
||||
|
||||
// Custom fields
|
||||
ReadCustomFields(c, t, "thing");
|
||||
|
|
|
@ -364,7 +364,7 @@ namespace CodeImp.DoomBuilder.Map
|
|||
ThingTypeInfo ti;
|
||||
|
||||
// Lookup settings
|
||||
ti = General.Map.Config.GetThingInfo(type);
|
||||
ti = General.Map.Data.GetThingInfo(type);
|
||||
|
||||
// Apply size
|
||||
size = ti.Width;
|
||||
|
|
|
@ -2075,7 +2075,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
if(IsInfoPanelExpanded) thinginfo.ShowInfo(t);
|
||||
|
||||
// Show info on collapsed label
|
||||
ThingTypeInfo ti = General.Map.Config.GetThingInfo(t.Type);
|
||||
ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
|
||||
labelcollapsedinfo.Text = t.Type + " - " + ti.Title;
|
||||
labelcollapsedinfo.Refresh();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
// Go for all predefined categories
|
||||
typelist.Nodes.Clear();
|
||||
nodes = new List<TreeNode>();
|
||||
foreach(ThingCategory tc in General.Map.Config.ThingCategories)
|
||||
foreach(ThingCategory tc in General.Map.Data.ThingCategories)
|
||||
{
|
||||
// Create category
|
||||
TreeNode cn = typelist.Nodes.Add(tc.Name, tc.Title);
|
||||
|
@ -283,7 +283,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
if(typeid.Text.Length > 0)
|
||||
{
|
||||
// Get the info
|
||||
ThingTypeInfo ti = General.Map.Config.GetThingInfoEx(typeid.GetResult(0));
|
||||
ThingTypeInfo ti = General.Map.Data.GetThingInfoEx(typeid.GetResult(0));
|
||||
if(ti != null)
|
||||
{
|
||||
knownthing = true;
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
|
||||
// Fill the categories combobox
|
||||
filtercategory.Items.Add("(any category)");
|
||||
filtercategory.Items.AddRange(General.Map.Config.ThingCategories.ToArray());
|
||||
filtercategory.Items.AddRange(General.Map.Data.ThingCategories.ToArray());
|
||||
|
||||
// Fill checkboxes list
|
||||
foreach(KeyValuePair<string, string> flag in General.Map.Config.ThingFlags)
|
||||
|
|
Loading…
Reference in a new issue