2012-07-10 10:20:45 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
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;
|
|
|
|
|
private readonly int index;
|
2015-02-24 13:38:35 +00:00
|
|
|
|
private readonly int cursorposition;
|
|
|
|
|
private readonly bool isinclude;
|
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; } }
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
2015-02-24 13:38:35 +00:00
|
|
|
|
internal ScriptItem(int index, 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;
|
|
|
|
|
this.index = index;
|
2015-02-24 13:38:35 +00:00
|
|
|
|
this.cursorposition = cursorPosition;
|
|
|
|
|
this.isinclude = isinclude;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
internal ScriptItem(int index, string name)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
this.name = name;
|
|
|
|
|
this.index = index;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
internal static int SortByIndex(ScriptItem i1, ScriptItem i2)
|
|
|
|
|
{
|
2015-02-24 13:38:35 +00:00
|
|
|
|
if (i1.isinclude && !i2.isinclude) return 1;
|
|
|
|
|
if (!i1.isinclude && i2.isinclude) return -1;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if (i1.Index > i2.Index) return 1;
|
|
|
|
|
if (i1.Index == i2.Index) return 0;
|
|
|
|
|
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-02-24 13:38:35 +00:00
|
|
|
|
if (i1.isinclude && !i2.isinclude) return 1;
|
|
|
|
|
if (!i1.isinclude && i2.isinclude) return -1;
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if (i1.Name == i2.Name) return 0;
|
|
|
|
|
if (i1.Name.ToUpper()[0] > i2.Name.ToUpper()[0]) return 1;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (i1.Name.ToUpper()[0] == i2.Name.ToUpper()[0])
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
int len = Math.Min(i1.Name.Length, i2.Name.Length);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
|
{
|
2013-09-11 09:47: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;
|
|
|
|
|
}
|
|
|
|
|
if (i1.Name.Length > i2.Name.Length) return 1;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|