2012-07-10 10:20:45 +00:00
|
|
|
|
using System;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
using System.Collections.Generic;
|
2012-07-10 10:20:45 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Data
|
|
|
|
|
{
|
|
|
|
|
internal sealed class ScriptItem : Object
|
|
|
|
|
{
|
2015-01-22 19:03:21 +00:00
|
|
|
|
private readonly string name;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
private readonly List<string> argnames;
|
2015-01-22 19:03:21 +00:00
|
|
|
|
private readonly int index;
|
2015-02-24 13:38:35 +00:00
|
|
|
|
private readonly int cursorposition;
|
|
|
|
|
private readonly bool isinclude;
|
2015-07-28 15:04:21 +00:00
|
|
|
|
private readonly bool customname;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
|
|
|
|
internal string Name { get { return name; } }
|
|
|
|
|
internal int Index { get { return index; } }
|
2015-02-24 13:38:35 +00:00
|
|
|
|
internal int CursorPosition { get { return cursorposition; } }
|
|
|
|
|
internal bool IsInclude { get { return isinclude; } }
|
2015-07-28 15:04:21 +00:00
|
|
|
|
internal bool HasCustomName { get { return customname; } }
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
2015-07-28 15:04:21 +00:00
|
|
|
|
// Constructor for misc usage
|
2015-07-27 09:02:28 +00:00
|
|
|
|
internal ScriptItem(string name, int cursorposition, bool isinclude)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
this.name = name;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
this.argnames = new List<string>();
|
|
|
|
|
this.index = int.MinValue;
|
|
|
|
|
this.cursorposition = cursorposition;
|
2015-02-24 13:38:35 +00:00
|
|
|
|
this.isinclude = isinclude;
|
2015-07-28 15:04:21 +00:00
|
|
|
|
this.customname = true;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-28 15:04:21 +00:00
|
|
|
|
// Constructor for numbered script
|
|
|
|
|
internal ScriptItem(int index, string name, List<string> argnames, int cursorposition, bool isinclude, bool customname)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
this.name = name;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
this.argnames = argnames;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
this.index = index;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
this.cursorposition = cursorposition;
|
|
|
|
|
this.isinclude = isinclude;
|
2015-07-28 15:04:21 +00:00
|
|
|
|
this.customname = customname;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-28 15:04:21 +00:00
|
|
|
|
// Constructor for named script
|
2015-07-27 09:02:28 +00:00
|
|
|
|
internal ScriptItem(string name, List<string> argnames, int cursorposition, bool isinclude)
|
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.argnames = argnames;
|
|
|
|
|
this.index = int.MinValue;
|
|
|
|
|
this.cursorposition = cursorposition;
|
|
|
|
|
this.isinclude = isinclude;
|
2015-07-28 15:04:21 +00:00
|
|
|
|
this.customname = true;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
internal static int SortByIndex(ScriptItem i1, ScriptItem i2)
|
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(i1.isinclude && !i2.isinclude) return 1;
|
|
|
|
|
if(!i1.isinclude && i2.isinclude) return -1;
|
|
|
|
|
if(i1.Index > i2.Index) return 1;
|
|
|
|
|
if(i1.Index == i2.Index) return 0;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 13:38:35 +00:00
|
|
|
|
internal static int SortByName(ScriptItem i1, ScriptItem i2)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(i1.isinclude && !i2.isinclude) return 1;
|
|
|
|
|
if(!i1.isinclude && i2.isinclude) return -1;
|
2015-02-24 13:38:35 +00:00
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(i1.Name == i2.Name) return 0;
|
|
|
|
|
if(i1.Name.ToUpper()[0] > i2.Name.ToUpper()[0]) return 1;
|
|
|
|
|
if(i1.Name.ToUpper()[0] == i2.Name.ToUpper()[0])
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
int len = Math.Min(i1.Name.Length, i2.Name.Length);
|
2015-12-28 15:01:53 +00:00
|
|
|
|
for(int i = 0; i < len; i++)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(i1.Name.ToUpper()[i] > i2.Name.ToUpper()[i]) return 1;
|
|
|
|
|
if(i1.Name.ToUpper()[i] < i2.Name.ToUpper()[i]) return -1;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(i1.Name.Length > i2.Name.Length) return 1;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-27 09:02:28 +00:00
|
|
|
|
// God awful, but will do...
|
2017-02-23 11:54:42 +00:00
|
|
|
|
// [ZZ] for backwards compatibility with broken maxed's code
|
|
|
|
|
internal string[] GetArgumentsDescriptions(int action)
|
|
|
|
|
{
|
|
|
|
|
int first;
|
|
|
|
|
return GetArgumentsDescriptions(action, out first);
|
|
|
|
|
}
|
|
|
|
|
internal string[] GetArgumentsDescriptions(int action, out int first)
|
2015-07-27 09:02:28 +00:00
|
|
|
|
{
|
|
|
|
|
string[] result = new[] { index == int.MinValue ? "Script Name" : "Script Number", string.Empty, string.Empty, string.Empty, string.Empty };
|
2017-02-23 11:54:42 +00:00
|
|
|
|
first = 0;
|
2015-12-28 15:01:53 +00:00
|
|
|
|
switch(action)
|
2015-07-27 09:02:28 +00:00
|
|
|
|
{
|
|
|
|
|
case 80: //ACS_Execute (script, map, s_arg1, s_arg2, s_arg3)
|
|
|
|
|
case 226: //ACS_ExecuteAlways (script, map, s_arg1, s_arg2, s_arg3)
|
|
|
|
|
argnames.CopyTo(0, result, 2, argnames.Count < 3 ? argnames.Count : 3);
|
2017-02-23 11:54:42 +00:00
|
|
|
|
first = 2;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 83: //ACS_LockedExecute (script, map, s_arg1, s_arg2, lock)
|
|
|
|
|
case 85: //ACS_LockedExecuteDoor (script, map, s_arg1, s_arg2, lock)
|
|
|
|
|
argnames.CopyTo(0, result, 2, argnames.Count < 2 ? argnames.Count : 2);
|
2017-02-23 11:54:42 +00:00
|
|
|
|
first = 2;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 84: //ACS_ExecuteWithResult (script, s_arg1, s_arg2, s_arg3, s_arg4)
|
|
|
|
|
argnames.CopyTo(0, result, 1, argnames.Count < 4 ? argnames.Count : 4);
|
2017-02-23 11:54:42 +00:00
|
|
|
|
first = 1;
|
2015-07-27 09:02:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 81: //ACS_Suspend (script, map)
|
|
|
|
|
case 82: //ACS_Terminate (script, map)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return new[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-10 10:20:45 +00:00
|
|
|
|
}
|