Skip to content

Commit 802adf4

Browse files
authored
Merge pull request #7 from Preagonal/updates2
Updates
2 parents 04fb8a3 + b5a7bec commit 802adf4

File tree

5 files changed

+83
-29
lines changed

5 files changed

+83
-29
lines changed

GS2Engine/Extensions/StackEntryExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace GS2Engine.Extensions
99
{
1010
public static class StackEntryExtensions
1111
{
12-
public static StackEntry ToStackEntry(this object stackObject, bool isVariable = false) =>
12+
public static StackEntry ToStackEntry(this object? stackObject, bool isVariable = false) =>
1313
new(isVariable ? StackEntryType.Variable : GetStackEntryType(stackObject), FixStackValue(stackObject));
1414

15-
private static object FixStackValue(object stackObject)
15+
private static object? FixStackValue(object? stackObject)
1616
{
1717
return stackObject switch
1818
{
@@ -28,9 +28,9 @@ private static object FixStackValue(object stackObject)
2828
};
2929
}
3030

31-
private static StackEntryType GetStackEntryType(object stackObject)
31+
private static StackEntryType GetStackEntryType(object? stackObject)
3232
{
33-
switch (Type.GetTypeCode(stackObject.GetType()))
33+
switch (Type.GetTypeCode(stackObject?.GetType()))
3434
{
3535
case TypeCode.Boolean:
3636
return StackEntryType.Boolean;
@@ -51,15 +51,15 @@ private static StackEntryType GetStackEntryType(object stackObject)
5151
return StackEntryType.String;
5252
default:
5353
{
54-
Type stackType = stackObject.GetType();
54+
Type? stackType = stackObject?.GetType();
5555
if (stackType == typeof(TString))
5656
return StackEntryType.String;
5757

5858
if (stackType == typeof(Script.Command))
5959
return StackEntryType.Function;
6060

61-
if (stackType.GetInterfaces()
62-
.Any(x => x.Name.Equals("IGuiControl", StringComparison.CurrentCultureIgnoreCase)))
61+
if (stackType != null && stackType.GetInterfaces()
62+
.Any(x => x.Name.Equals("IGuiControl", StringComparison.CurrentCultureIgnoreCase)))
6363
return StackEntryType.Array;
6464

6565
if (stackType == typeof(VariableCollection))
@@ -68,7 +68,7 @@ private static StackEntryType GetStackEntryType(object stackObject)
6868
if (stackObject is float)
6969
return StackEntryType.Number;
7070

71-
if (stackType.IsGenericType &&
71+
if (stackType is { IsGenericType: true } &&
7272
stackType.GetGenericTypeDefinition().IsAssignableFrom(typeof(List<>)))
7373
return StackEntryType.Array;
7474

GS2Engine/GS2/Script/Script.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ public Script(
3535

3636
Init(objects, variables, functions);
3737
}
38+
39+
public Script(
40+
TString name,
41+
byte[] bytecode,
42+
IDictionary<string, VariableCollection>? objects,
43+
VariableCollection? variables,
44+
Dictionary<string, Command>? functions
45+
)
46+
{
47+
Name = name;
48+
File = "";
49+
Machine = new(this);
50+
SetStream(bytecode);
51+
52+
Init(objects, variables, functions);
53+
}
3854

3955
private int BytecodeLength => _bytecode.Length;
4056

@@ -62,12 +78,15 @@ public void UpdateFromFile(
6278
}
6379

6480
public void UpdateFromByteCode(
81+
TString name,
6582
byte[] byteCode,
6683
IDictionary<string, VariableCollection>? objects,
6784
VariableCollection? variables,
6885
Dictionary<string, Command>? functions
6986
)
7087
{
88+
Name = name;
89+
File = "";
7190
SetStream(byteCode);
7291

7392
Init(objects, variables, functions);
@@ -105,9 +124,7 @@ private void Init(
105124
private void Reset()
106125
{
107126
Machine.Reset();
108-
//GlobalVariables.Clear();
109127
Functions.Clear();
110-
GlobalObjects.Clear();
111128
ExternalFunctions?.Clear();
112129
_bytecode = Array.Empty<ScriptCom>();
113130
}
@@ -269,6 +286,7 @@ private void SetStream(TString bytecodeParam)
269286
doubleString.writeChar(ch);
270287
}
271288

289+
doubleString = doubleString.ToString().Replace("--", "");
272290
op.Value = double.Parse(doubleString.ToString(), CultureInfo.InvariantCulture);
273291
Tools.Debug($" - double({op.Value}) (string)\n");
274292
break;

GS2Engine/GS2/Script/ScriptMachine.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task<IStackEntry> Execute(string functionName, Stack<IStackEntry>?
4444
IStackEntry? opCopy = null;
4545
Stack<IStackEntry> opWith = new();
4646

47-
Tools.DebugLine($"Starting to execute function \"{functionName}\"");
47+
Tools.DebugLine($"Starting to execute function \"{_script.Name}.{functionName}\"");
4848
while (index < _script.Bytecode.Length)
4949
{
5050
int curIndex = index;
@@ -205,9 +205,7 @@ out Script.Command command
205205
IStackEntry ret = 0.ToStackEntry();
206206
if (stack.Count > 0)
207207
ret = stack.Pop();
208-
Tools.DebugLine(
209-
JsonConvert.SerializeObject(Script.GlobalVariables.GetDictionary(), Formatting.Indented)
210-
);
208+
211209
return ret;
212210
case Opcode.OP_SLEEP:
213211
double sleep = getEntryValue<double>(stack.Pop());

GS2Engine/Models/GuiControl.cs

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ public bool Editing
9898
set => AddOrUpdate("editing", value.ToStackEntry());
9999
}
100100

101-
public string extent { get; set; }
101+
public string Extent
102+
{
103+
get => GetVariable("extent").GetValue<TString>() ?? string.Empty;
104+
set => AddOrUpdate("extent", value.ToStackEntry());
105+
}
102106

103107
public bool Flickering
104108
{
@@ -112,13 +116,37 @@ public int FlickerTime
112116
set => AddOrUpdate("flickertime", value.ToStackEntry());
113117
}
114118

115-
public string hint { get; set; }
116-
public string horizsizing { get; set; }
119+
public string Hint
120+
{
121+
get => GetVariable("hint").GetValue<TString>() ?? string.Empty;
122+
set => AddOrUpdate("hint", value.ToStackEntry());
123+
}
124+
public string HorizSizing
125+
{
126+
get => GetVariable("horizsizing").GetValue<TString>() ?? string.Empty;
127+
set => AddOrUpdate("horizsizing", value.ToStackEntry());
128+
}
117129
public int layer { get; }
118-
public string minextent { get; set; }
119-
public string minsize { get; set; }
120-
public string position { get; set; }
121-
public object profile { get; set; }
130+
public string MinExtent
131+
{
132+
get => GetVariable("minextent").GetValue<TString>() ?? string.Empty;
133+
set => AddOrUpdate("minextent", value.ToStackEntry());
134+
}
135+
public string MinSize
136+
{
137+
get => GetVariable("minsize").GetValue<TString>() ?? string.Empty;
138+
set => AddOrUpdate("minsize", value.ToStackEntry());
139+
}
140+
public string position
141+
{
142+
get => GetVariable("position").GetValue<TString>() ?? string.Empty;
143+
set => AddOrUpdate("position", value.ToStackEntry());
144+
}
145+
public IGuiControl? profile
146+
{
147+
get => GetVariable("profile").GetValue<IGuiControl>();
148+
set => AddOrUpdate("profile", value.ToStackEntry());
149+
}
122150

123151
public bool ResizeHeight
124152
{
@@ -147,7 +175,11 @@ public bool UseOwnProfile
147175
set => AddOrUpdate("useownprofile", value.ToStackEntry());
148176
}
149177

150-
public string vertsizing { get; set; }
178+
public string vertsizing
179+
{
180+
get => GetVariable("vertsizing").GetValue<TString>() ?? string.Empty;
181+
set => AddOrUpdate("vertsizing", value.ToStackEntry());
182+
}
151183

152184
public bool Visible
153185
{
@@ -194,14 +226,20 @@ public void Destroy()
194226
Dispose();
195227
}
196228

197-
public IGuiControl parent { get; set; }
229+
public IGuiControl? parent
230+
{
231+
get => GetVariable("parent").GetValue<IGuiControl>();
232+
set => AddOrUpdate("parent", value.ToStackEntry());
233+
}
198234

199235
public void AddControl(IGuiControl? obj)
200236
{
201237
if (obj == null) return;
202-
203238
obj.parent = this;
204-
Controls.Add(obj);
239+
lock (Controls)
240+
{
241+
Controls.Add(obj);
242+
}
205243
}
206244

207245
public virtual void Draw()

GS2Engine/Models/IGuiControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ namespace GS2Engine.Models
22
{
33
public interface IGuiControl
44
{
5-
public IGuiControl parent { get; set; }
6-
public void Draw();
7-
void Destroy();
8-
public void AddControl(IGuiControl? obj);
5+
public IGuiControl? parent { get; set; }
6+
public void Draw();
7+
void Destroy();
8+
public void AddControl(IGuiControl? obj);
99
}
1010
}

0 commit comments

Comments
 (0)