mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-27 14:12:16 +00:00
88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using CodeImp.DoomBuilder.IO;
|
|
using System.Collections.Specialized;
|
|
|
|
namespace CodeImp.DoomBuilder.Images
|
|
{
|
|
internal class ResourceLocationList : List<ResourceLocation>
|
|
{
|
|
#region ================== Constructors
|
|
|
|
// This creates a new list
|
|
public ResourceLocationList()
|
|
{
|
|
}
|
|
|
|
// This creates a list from a configuration structure
|
|
public ResourceLocationList(Configuration cfg, string path)
|
|
{
|
|
IDictionary resinfo, rlinfo;
|
|
ResourceLocation res;
|
|
|
|
// Go for all items in the map info
|
|
resinfo = cfg.ReadSetting(path, new ListDictionary());
|
|
foreach(DictionaryEntry rl in resinfo)
|
|
{
|
|
// Item is a structure?
|
|
if(rl.Value is IDictionary)
|
|
{
|
|
// Create resource location
|
|
rlinfo = (IDictionary)rl.Value;
|
|
res = new ResourceLocation();
|
|
|
|
// Copy information from Configuration to ResourceLocation
|
|
if(rlinfo.Contains("type") && (rlinfo["type"] is int)) res.type = (int)rlinfo["type"];
|
|
if(rlinfo.Contains("location") && (rlinfo["location"] is string)) res.location = (string)rlinfo["location"];
|
|
if(rlinfo.Contains("textures") && (rlinfo["textures"] is bool)) res.textures = (bool)rlinfo["textures"];
|
|
if(rlinfo.Contains("flats") && (rlinfo["flats"] is bool)) res.flats = (bool)rlinfo["flats"];
|
|
|
|
// Add resource
|
|
Add(res);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ================== Methods
|
|
|
|
// This merges two lists together
|
|
public static ResourceLocationList Combined(ResourceLocationList a, ResourceLocationList b)
|
|
{
|
|
ResourceLocationList result = new ResourceLocationList();
|
|
result.AddRange(a);
|
|
result.AddRange(b);
|
|
return result;
|
|
}
|
|
|
|
// This writes the list to configuration
|
|
public void WriteToConfig(Configuration cfg, string path)
|
|
{
|
|
IDictionary resinfo, rlinfo;
|
|
|
|
// Fill structure
|
|
resinfo = new ListDictionary();
|
|
for(int i = 0; i < this.Count; i++)
|
|
{
|
|
// Create structure for resource
|
|
rlinfo = new ListDictionary();
|
|
rlinfo.Add("type", this[i].type);
|
|
rlinfo.Add("location", this[i].location);
|
|
rlinfo.Add("textures", this[i].textures);
|
|
rlinfo.Add("flats", this[i].flats);
|
|
|
|
// Add structure
|
|
resinfo.Add("resource" + i.ToString(CultureInfo.InvariantCulture), rlinfo);
|
|
}
|
|
|
|
// Write to config
|
|
cfg.WriteSetting(path, resinfo);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|