-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKM_ScriptingConsts.pas
More file actions
152 lines (126 loc) · 4.33 KB
/
KM_ScriptingConsts.pas
File metadata and controls
152 lines (126 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
unit KM_ScriptingConsts;
interface
uses
System.StrUtils, System.SysUtils;
function TryEventTypeToAlias(const aType: string): string;
function TryEventTypeToTyp(const aType: string): string;
function TryEventModifierToDir(const aModifier: string): string;
function TokenIsModifier(const aToken: string): Boolean;
function FixModifierCase(const aModifier: string): string;
function FixTypeCase(const aType: string): string;
implementation
type
TKMEventTypesInfo = record
TypeName: string;
PSBaseType: string; // Required for Events
end;
TKMEventAliasInfo = record
TypeName: string;
Alias: string; // Required for Events
end;
const
VAR_MODIFIERS: array [0..1] of string = ('out', 'var');
// PascalScript types of event variable types
VAR_TYPES_FOR_EVENTS: array [0..19] of TKMEventTypesInfo = (
(TypeName: 'Byte'; PSBaseType: 'btS32'),
(TypeName: 'ShortInt'; PSBaseType: 'btS32'),
(TypeName: 'SmallInt'; PSBaseType: 'btS32'),
(TypeName: 'Word'; PSBaseType: 'btS32'),
(TypeName: 'Integer'; PSBaseType: 'btS32'),
(TypeName: 'Cardinal'; PSBaseType: 'btS32'),
(TypeName: 'Boolean'; PSBaseType: 'btEnum'),
(TypeName: 'Single'; PSBaseType: 'btSingle'),
// Common
(TypeName: 'TKMFieldType'; PSBaseType: 'btEnum'),
(TypeName: 'TKMHouseType'; PSBaseType: 'btEnum'),
(TypeName: 'TKMUnitType'; PSBaseType: 'btEnum'),
(TypeName: 'TKMWareType'; PSBaseType: 'btEnum'),
// KMR
(TypeName: 'TKMDirection'; PSBaseType: 'btEnum'),
(TypeName: 'TKMDeliveryMode'; PSBaseType: 'btEnum'),
(TypeName: 'TKMWoodcutterMode'; PSBaseType: 'btEnum'),
// KP
(TypeName: 'AnsiString'; PSBaseType: 'btString'),
(TypeName: 'TKMHouseFace'; PSBaseType: 'btEnum'),
(TypeName: 'TKMObjectiveStatus'; PSBaseType: 'btEnum'),
(TypeName: 'TKMObjectiveType'; PSBaseType: 'btEnum'),
(TypeName: 'TKMFenceType'; PSBaseType: 'btEnum')
);
// Aliases for Event variable types
VAR_ALIASES_FOR_EVENTS: array [0..7] of TKMEventAliasInfo = (
// Common
(TypeName: 'TKMHouse'; Alias: 'Integer'),
(TypeName: 'TKMUnit'; Alias: 'Integer'),
(TypeName: 'TKMUnitGroup'; Alias: 'Integer'),
// KMR
(TypeName: 'TKMHandID'; Alias: 'Integer'),
(TypeName: 'array of TKMHandID'; Alias: 'array of Integer'),
// KP
(TypeName: 'TKMEntity'; Alias: 'Integer'),
(TypeName: 'TKMHandIndex'; Alias: 'Integer'),
(TypeName: 'array of TKMHandIndex'; Alias: 'array of Integer')
);
// Try to convert a type into alias
function TryEventTypeToAlias(const aType: string): string;
var
I: Integer;
begin
Result := aType;
for I := 0 to High(VAR_ALIASES_FOR_EVENTS) do
if SameText(VAR_ALIASES_FOR_EVENTS[I].TypeName, aType) then
Exit(VAR_ALIASES_FOR_EVENTS[I].Alias);
//Assert(False, Format('Type "%s" not found', [aType]));
end;
// Figure out types type for PascalScript
function TryEventTypeToTyp(const aType: string): string;
var
I: Integer;
begin
Result := '0';
for I := 0 to High(VAR_TYPES_FOR_EVENTS) do
if SameText(VAR_TYPES_FOR_EVENTS[I].TypeName, aType) then
Exit(VAR_TYPES_FOR_EVENTS[I].PSBaseType);
Assert(False, Format('Type "%s" not found', [aType]));
end;
function TryEventModifierToDir(const aModifier: string): string;
begin
if aModifier = '' then
Result := 'pmIn'
else
if aModifier = 'var' then
Result := 'pmInOut'
else
if aModifier = 'out' then
Result := 'pmOut'
else
Assert(False, Format('Modifier "%s" not found', [aModifier]));
end;
function TokenIsModifier(const aToken: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to High(VAR_MODIFIERS) do
if SameText(VAR_MODIFIERS[I], aToken) then
Exit(True);
end;
function FixModifierCase(const aModifier: string): string;
var
I: Integer;
begin
Result := aModifier;
for I := 0 to High(VAR_MODIFIERS) do
if SameText(VAR_MODIFIERS[I], aModifier) then
Exit(VAR_MODIFIERS[I]);
end;
function FixTypeCase(const aType: string): string;
begin
if aType = 'Shortint' then
Result := 'ShortInt'
else
if aType = 'String' then
Result := 'string'
else
Result := aType;
end;
end.