allow whitespace in create item masks

This commit is contained in:
Martin Michelsen
2025-11-28 12:41:25 -08:00
parent e02a006b60
commit 3ef91b0159
2 changed files with 17 additions and 14 deletions
+16 -8
View File
@@ -264,22 +264,30 @@ phosg::JSON QuestMetadata::json() const {
QuestMetadata::CreateItemMask::CreateItemMask(const std::string& s) {
phosg::StringReader r(s);
// Ignore all whitespace
auto get_ch = [&]() -> char {
char ch = r.get_s8();
while ((ch == ' ') || (ch == '\t')) {
ch = r.get_s8();
}
return ch;
};
for (size_t z = 0; z < 12 && !r.eof(); z++) {
auto& range = this->data1_ranges[z];
char c = r.get_s8();
char c = get_ch();
if (c == '[') {
c = r.get_s8();
range.min = (phosg::value_for_hex_char(c) << 4) | phosg::value_for_hex_char(r.get_s8());
if (r.get_s8() != '-') {
c = get_ch();
range.min = (phosg::value_for_hex_char(c) << 4) | phosg::value_for_hex_char(get_ch());
if (get_ch() != '-') {
throw std::runtime_error("invalid range spec");
}
c = r.get_s8();
range.max = (phosg::value_for_hex_char(c) << 4) | phosg::value_for_hex_char(r.get_s8());
if (r.get_s8() != ']') {
c = get_ch();
range.max = (phosg::value_for_hex_char(c) << 4) | phosg::value_for_hex_char(get_ch());
if (get_ch() != ']') {
throw std::runtime_error("invalid range spec");
}
} else {
range.min = (phosg::value_for_hex_char(c) << 4) | phosg::value_for_hex_char(r.get_s8());
range.min = (phosg::value_for_hex_char(c) << 4) | phosg::value_for_hex_char(get_ch());
range.max = range.min;
}
}
+1 -6
View File
@@ -4279,12 +4279,7 @@ AssembledQuestScript assemble_quest_script(
if (ret.meta.create_item_mask_entries.size() >= 0x40) {
throw std::runtime_error("too many .allow_create_item directives; at most 64 are allowed");
}
string args_str = line.text.substr(19);
phosg::strip_whitespace(args_str);
QuestMetadata::CreateItemMask mask(line.text.substr(19));
ret.meta.create_item_mask_entries.emplace_back(mask);
ret.meta.create_item_mask_entries.emplace_back(line.text.substr(19));
} else if (line.text.starts_with(".quest_num ")) {
ret.meta.quest_number = stoul(line.text.substr(11), nullptr, 0);