2014-05-08 09:24:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
2012-11-27 23:04:49 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Types;
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Tools
|
|
|
|
|
{
|
|
|
|
|
public static class UDMFTools
|
|
|
|
|
{
|
|
|
|
|
//float
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void SetFloat(UniFields fields, string key, float value)
|
|
|
|
|
{
|
2013-09-05 13:03:17 +00:00
|
|
|
|
SetFloat(fields, key, value, 0f);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void SetFloat(UniFields fields, string key, float value, float defaultValue)
|
|
|
|
|
{
|
2012-11-27 23:04:49 +00:00
|
|
|
|
if(fields == null) return;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
2012-11-27 23:04:49 +00:00
|
|
|
|
if(!fields.ContainsKey(key))
|
|
|
|
|
fields.Add(key, new UniValue(UniversalType.Float, value));
|
|
|
|
|
else
|
|
|
|
|
fields[key].Value = value;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if(fields.ContainsKey(key)) //don't save default value
|
|
|
|
|
{
|
2012-11-27 23:04:49 +00:00
|
|
|
|
fields.Remove(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static float GetFloat(UniFields fields, string key)
|
|
|
|
|
{
|
2013-09-05 13:03:17 +00:00
|
|
|
|
return GetFloat(fields, key, 0f);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static float GetFloat(UniFields fields, string key, float defaultValue)
|
|
|
|
|
{
|
2013-06-10 14:04:23 +00:00
|
|
|
|
if(fields == null) return defaultValue;
|
|
|
|
|
return fields.GetValue(key, defaultValue);
|
|
|
|
|
}
|
2012-11-27 23:04:49 +00:00
|
|
|
|
|
2013-06-10 14:04:23 +00:00
|
|
|
|
//int
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void SetInteger(UniFields fields, string key, int value)
|
|
|
|
|
{
|
2013-09-05 13:03:17 +00:00
|
|
|
|
SetInteger(fields, key, value, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void SetInteger(UniFields fields, string key, int value, int defaultValue)
|
|
|
|
|
{
|
2012-11-27 23:04:49 +00:00
|
|
|
|
if(fields == null) return;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
2012-11-27 23:04:49 +00:00
|
|
|
|
if(!fields.ContainsKey(key))
|
|
|
|
|
fields.Add(key, new UniValue(UniversalType.Integer, value));
|
|
|
|
|
else
|
|
|
|
|
fields[key].Value = value;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if(fields.ContainsKey(key)) //don't save default value
|
|
|
|
|
{
|
2012-11-27 23:04:49 +00:00
|
|
|
|
fields.Remove(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-10 14:04:23 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static int GetInteger(UniFields fields, string key)
|
|
|
|
|
{
|
2013-09-05 13:03:17 +00:00
|
|
|
|
return GetInteger(fields, key, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static int GetInteger(UniFields fields, string key, int defaultValue)
|
|
|
|
|
{
|
2013-06-10 14:04:23 +00:00
|
|
|
|
if(fields == null) return defaultValue;
|
|
|
|
|
return fields.GetValue(key, defaultValue);
|
|
|
|
|
}
|
2014-01-13 08:06:56 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void SetString(UniFields fields, string key, string value, string defaultValue)
|
|
|
|
|
{
|
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
|
|
|
|
if(fields == null) return;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
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
|
|
|
|
if(!fields.ContainsKey(key))
|
|
|
|
|
fields.Add(key, new UniValue(UniversalType.String, value));
|
|
|
|
|
else
|
|
|
|
|
fields[key].Value = value;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if(fields.ContainsKey(key)) //don't save default value
|
|
|
|
|
{
|
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
|
|
|
|
fields.Remove(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void ClearFields(UniFields fields, string[] keys)
|
|
|
|
|
{
|
2014-01-13 08:06:56 +00:00
|
|
|
|
if(fields == null) return;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(string key in keys)
|
|
|
|
|
{
|
2014-01-13 08:06:56 +00:00
|
|
|
|
if(fields.ContainsKey(key)) fields.Remove(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static void ClearField(UniFields fields, string key)
|
|
|
|
|
{
|
2014-01-13 08:06:56 +00:00
|
|
|
|
if(fields == null || !fields.ContainsKey(key)) return;
|
|
|
|
|
fields.Remove(key);
|
|
|
|
|
}
|
2014-05-08 09:24:32 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static bool FieldsMatch(UniFields fields1, UniFields fields2)
|
|
|
|
|
{
|
2014-05-08 09:24:32 +00:00
|
|
|
|
if (fields1.Keys.Count != fields2.Keys.Count) return false;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(KeyValuePair<string, UniValue> group in fields1)
|
|
|
|
|
{
|
2014-05-08 09:24:32 +00:00
|
|
|
|
if (!fields2.ContainsKey(group.Key)) return false;
|
|
|
|
|
if (fields2[group.Key].Type != fields1[group.Key].Type) return false;
|
|
|
|
|
|
|
|
|
|
if (fields1[group.Key].Value is int)
|
|
|
|
|
{
|
|
|
|
|
if ((int)fields1[group.Key].Value != (int)fields2[group.Key].Value) return false;
|
|
|
|
|
}
|
|
|
|
|
else if (fields1[group.Key].Value is float)
|
|
|
|
|
{
|
|
|
|
|
if((float)fields1[group.Key].Value != (float)fields2[group.Key].Value) return false;
|
|
|
|
|
}
|
|
|
|
|
else if(fields1[group.Key].Value is bool)
|
|
|
|
|
{
|
|
|
|
|
if((bool)fields1[group.Key].Value != (bool)fields2[group.Key].Value) return false;
|
|
|
|
|
}
|
|
|
|
|
else if (fields1[group.Key].Value is string)
|
|
|
|
|
{
|
|
|
|
|
if ((string)fields1[group.Key].Value != (string)fields2[group.Key].Value) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Got unknown Custom Field type to compare: " + fields1[group.Key].Value.GetType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-11-27 23:04:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|