Skip to content

Commit 8315f2b

Browse files
fix(fgdpp): add support for modifiers in entity keyvalues, implement strata fgd extension
1 parent fd8f37e commit 8315f2b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

include/fgdpp/fgdpp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class FGD {
2424
struct Field {
2525
std::string_view name;
2626
std::string_view valueType;
27+
std::string_view modifier;
2728
std::string_view displayName;
2829
std::string_view valueDefault;
2930
std::string_view description;
@@ -36,6 +37,7 @@ class FGD {
3637
};
3738

3839
std::string_view name;
40+
std::string_view modifier;
3941
std::string_view displayName;
4042
std::string_view valueDefault;
4143
std::string_view description;
@@ -51,6 +53,9 @@ class FGD {
5153
};
5254

5355
std::string_view name;
56+
std::string_view modifier;
57+
std::string_view displayName;
58+
std::string_view description;
5459
std::vector<Flag> flags;
5560
};
5661

src/fgdpp/fgdpp.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ void readEntityIO(BufferStreamReadOnly& stream, BufferStream& backing, FGD::Enti
184184
parser::text::eatWhitespaceAndSingleLineComments(stream);
185185
}
186186

187+
[[nodiscard]] std::string_view readEntityFieldModifier(BufferStreamReadOnly& stream, BufferStream& backing) {
188+
parser::text::eatWhitespace(stream);
189+
if (stream.peek<char>() != ':' && stream.peek<char>() != '=') {
190+
return parser::text::readUnquotedStringToBuffer(stream, backing);
191+
}
192+
return "";
193+
}
194+
187195
void readEntityKeyValue(BufferStreamReadOnly& stream, BufferStream& backing, FGD::Entity& entity) {
188196
// Key and value type (looks like "key(valueType)", or "input key(valueType)" for i/o)
189197
auto name = parser::text::readUnquotedStringToBuffer(stream, backing, "(", parser::text::NO_ESCAPE_SEQUENCES);
@@ -205,6 +213,7 @@ void readEntityKeyValue(BufferStreamReadOnly& stream, BufferStream& backing, FGD
205213
if (string::iequals(valueType, "choices")) {
206214
auto& field = entity.fieldsWithChoices.emplace_back();
207215
field.name = name;
216+
field.modifier = ::readEntityFieldModifier(stream, backing);
208217

209218
if (::tryToEatSeparator(stream, ':')) {
210219
field.displayName = ::readFGDString(stream, backing);
@@ -238,6 +247,17 @@ void readEntityKeyValue(BufferStreamReadOnly& stream, BufferStream& backing, FGD
238247
} else if (string::iequals(valueType, "flags")) {
239248
auto& field = entity.fieldsWithFlags.emplace_back();
240249
field.name = name;
250+
field.modifier = ::readEntityFieldModifier(stream, backing);
251+
252+
if (::tryToEatSeparator(stream, ':')) {
253+
field.displayName = ::readFGDString(stream, backing);
254+
parser::text::eatWhitespaceAndSingleLineComments(stream);
255+
}
256+
257+
if (::tryToEatSeparator(stream, ':')) {
258+
field.description = ::readFGDString(stream, backing);
259+
parser::text::eatWhitespaceAndSingleLineComments(stream);
260+
}
241261

242262
if (!::tryToEatSeparator(stream, '=') || !::tryToEatSeparator(stream, '[')) {
243263
throw parser::text::syntax_error{INVALID_SYNTAX_MSG};
@@ -246,7 +266,7 @@ void readEntityKeyValue(BufferStreamReadOnly& stream, BufferStream& backing, FGD
246266

247267
while (stream.peek<char>() != ']') {
248268
auto& flag = field.flags.emplace_back();
249-
flag.value = parser::text::readUnquotedStringToBuffer(stream, backing, parser::text::NO_ESCAPE_SEQUENCES);
269+
flag.value = ::readFGDString(stream, backing);
250270

251271
if (!::tryToEatSeparator(stream, ':')) {
252272
continue;
@@ -256,7 +276,7 @@ void readEntityKeyValue(BufferStreamReadOnly& stream, BufferStream& backing, FGD
256276
if (!::tryToEatSeparator(stream, ':')) {
257277
continue;
258278
}
259-
flag.enabledByDefault = parser::text::readUnquotedStringToBuffer(stream, backing, parser::text::NO_ESCAPE_SEQUENCES);
279+
flag.enabledByDefault = ::readFGDString(stream, backing);
260280

261281
if (!::tryToEatSeparator(stream, ':')) {
262282
continue;
@@ -268,6 +288,7 @@ void readEntityKeyValue(BufferStreamReadOnly& stream, BufferStream& backing, FGD
268288
auto& field = entity.fields.emplace_back();
269289
field.name = name;
270290
field.valueType = valueType;
291+
field.modifier = ::readEntityFieldModifier(stream, backing);
271292
field.displayName = "";
272293
field.valueDefault = "";
273294
field.description = "";

test/res/fgdpp/ideal.fgd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"An entity that can be linked to another door and create a passage between them dynamically.\n" +
1111
"This is a separate line!"
1212
[
13-
portal1(int)
13+
portal1(int) readonly
1414
portal2(int) : "Portal 2"
1515
portal3(int) : "Portal 3" : "0"
16-
portal4(int) : "Portal 4" : "0" : "This is the wonderful world of Portal " +
17-
"4"
16+
portal4(int) report : "Portal 4" : "0" : "This is the wonderful world of Portal " +
17+
"4"
1818

1919
input portalInput1(string)
2020
input portalInput2(string) : "Portal Input 2"
@@ -31,7 +31,7 @@
3131
8 : "nothing" : 1
3232
]
3333

34-
model(choices) : "Model used" : "models/something02.mdl" =
34+
model(choices) readonly : "Model used" : "models/something02.mdl" =
3535
[
3636
"models/something01.mdl" : "something"
3737
"models/something02.mdl" : "something else (default)"
@@ -51,6 +51,14 @@
5151
]
5252

5353
output portalOutput3(string) : "Portal Output 3"
54+
55+
effects(flags) : "Effects" : "These sure are effects" =
56+
[
57+
0: "None" : 0
58+
1: "Always, very expensive!" : 0
59+
2: "Bright, dynamic light at entity origin" : 0
60+
4: "Dim, dynamic light at entity origin" : 0
61+
]
5462
]
5563

5664
@MaterialExclusion

0 commit comments

Comments
 (0)