Compare commits

..

No commits in common. "135c7dd99969e6afcc6ee755e6aea6c80e3fb06d" and "343fe13e68a233c690364fee6e181847dfe0c81b" have entirely different histories.

4 changed files with 35 additions and 55 deletions

View File

@ -42,7 +42,7 @@ function patch(config)
shift(clone(layout, "multiTextureLabel", "hardwareCursorLabel"), 98, -11).value = "HARDWARE CURSOR" shift(clone(layout, "multiTextureLabel", "hardwareCursorLabel"), 98, -11).value = "HARDWARE CURSOR"
shift(clone(layout, "multiTextureCheckbox", "hardwareCursorCheckbox"), 99, -11) shift(clone(layout, "multiTextureCheckbox", "hardwareCursorCheckbox"), 99, -11)
shift(layout.title, 0, 24) shift(layout.title, 0, 28)
shift(layout.resLabel, 0, 28) shift(layout.resLabel, 0, 28)
shift(layout.resSlider, 0, 28) shift(layout.resSlider, 0, 28)
shift(layout.resValueLabel, 0, 28) shift(layout.resValueLabel, 0, 28)

View File

@ -39,7 +39,7 @@ template <typename InputIterator>
class JsonParser { class JsonParser {
public: public:
JsonParser(JsonStream& stream) JsonParser(JsonStream& stream)
: m_line(0), m_column(0), m_stream(stream), m_error(nullptr) {} : m_line(0), m_column(0), m_stream(stream) {}
virtual ~JsonParser() {} virtual ~JsonParser() {}
// Does not throw. On error, returned iterator will not be equal to end, and // Does not throw. On error, returned iterator will not be equal to end, and
@ -65,7 +65,10 @@ public:
// Human readable parsing error, does not include line or column info. // Human readable parsing error, does not include line or column info.
char const* error() const { char const* error() const {
return m_error; if (m_error.empty())
return nullptr;
else
return m_error.c_str();
} }
size_t line() const { size_t line() const {
@ -213,42 +216,31 @@ private:
break; break;
else { else {
auto begin = m_current; auto begin = m_current;
auto b_char = m_char;
if (m_char >= '0' && m_char <= '9') { if (m_char >= '0' && m_char <= '9') {
try { number();
number(true); if (m_error.empty()) {
}
catch (ParsingException const&) {
m_current = begin;
m_char = b_char;
}
if (m_error == nullptr) {
next(); next();
continue; continue;
} }
} }
m_error = nullptr; m_error.clear();
m_current = begin;
if (m_char == 't' || m_char == 'f' || m_char == 'n') { if (m_char == 't' || m_char == 'f' || m_char == 'n') {
try { word();
word(true); if (m_error.empty()) {
}
catch (ParsingException const&) {
m_current = begin;
m_char = b_char;
}
if (m_error == nullptr) {
next(); next();
continue; continue;
} }
} }
m_error = nullptr; m_error.clear();
m_current = begin;
// well, shit. do a simple string parse until we hit whitespace // well, shit. do a simple string parse until we hit whitespace
// no fancy things like \n, do a proper string if you want that // no fancy things like \n, do a proper string if you want that
CharArray str; CharArray str;
do { do {
str += m_char; str += m_char;
next(); next();
} while (m_char != 0 && !isSpace(m_char)); } while (m_char && !isSpace(m_char));
m_stream.putString(str.c_str(), str.length()); m_stream.putString(str.c_str(), str.length());
} }
next(); next();
@ -261,7 +253,7 @@ private:
m_stream.putString(s.c_str(), s.length()); m_stream.putString(s.c_str(), s.length());
} }
void number(bool seq = false) { void number() {
std::basic_string<char32_t> buffer; std::basic_string<char32_t> buffer;
bool isDouble = false; bool isDouble = false;
@ -305,35 +297,30 @@ private:
next(); next();
} }
} }
if (seq && m_char != 0 && !isSpace(m_char))
error("unexpected character after number");
if (isDouble) { if (isDouble) {
try { try {
m_stream.putDouble(buffer.c_str(), buffer.length()); m_stream.putDouble(buffer.c_str(), buffer.length());
} catch (std::exception const& e) { } catch (std::exception const& e) {
error("bad double"); error(std::string("Bad double: ") + e.what());
} }
} else { } else {
try { try {
m_stream.putInteger(buffer.c_str(), buffer.length()); m_stream.putInteger(buffer.c_str(), buffer.length());
} catch (std::exception const& e) { } catch (std::exception const& e) {
error("bad integer"); error(std::string("Bad integer: ") + e.what());
} }
} }
} }
// true, false, or null // true, false, or null
void word(bool seq = false) { void word() {
switch (m_char) { switch (m_char) {
case 't': case 't':
next(); next();
check('r'); check('r');
check('u'); check('u');
check('e'); check('e');
if (seq && m_char != 0 && !isSpace(m_char))
error("unexpected character after word");
m_stream.putBoolean(true); m_stream.putBoolean(true);
break; break;
case 'f': case 'f':
@ -342,8 +329,6 @@ private:
check('l'); check('l');
check('s'); check('s');
check('e'); check('e');
if (seq && m_char != 0 && !isSpace(m_char))
error("unexpected character after word");
m_stream.putBoolean(false); m_stream.putBoolean(false);
break; break;
case 'n': case 'n':
@ -351,8 +336,6 @@ private:
check('u'); check('u');
check('l'); check('l');
check('l'); check('l');
if (seq && m_char != 0 && !isSpace(m_char))
error("unexpected character after word");
m_stream.putNull(); m_stream.putNull();
break; break;
default: default:
@ -519,32 +502,34 @@ private:
} }
} else { } else {
// The only allowed characters following / in whitespace are / and * // The only allowed characters following / in whitespace are / and *
error("/ character in whitespace is not followed by '/' or '*', invalid comment"); error("/ character in whitespace is not follwed by '/' or '*', invalid comment");
return; return;
} }
} else if (isSpace(m_char)) { } else if (isSpace(m_char)) {
buffer += m_char; buffer += m_char;
next(); next();
} else { } else {
break; if (buffer.size() != 0)
m_stream.putWhitespace(buffer.c_str(), buffer.length());
return;
} }
} }
if (buffer.size() != 0) if (buffer.size() != 0)
m_stream.putWhitespace(buffer.c_str(), buffer.length()); m_stream.putWhitespace(buffer.c_str(), buffer.length());
} }
void error(const char* msg) { void error(std::string msg) {
m_error = msg; m_error = std::move(msg);
throw ParsingException(); throw ParsingException();
} }
bool isSpace(char32_t c) { bool isSpace(char32_t c) {
// Only whitespace allowed by JSON // Only whitespace allowed by JSON
return c == 0x20 || // space return c == 0x20 || // space
c == 0x09 || // horizontal tab c == 0x09 || // horizontal tab
c == 0x0a || // newline c == 0x0a || // newline
c == 0x0d || // carriage return c == 0x0d || // carriage return
c == 0xfeff; // BOM or ZWNBSP c == 0xfeff; // BOM or ZWNBSP
} }
char32_t m_char; char32_t m_char;
@ -552,7 +537,7 @@ private:
InputIterator m_end; InputIterator m_end;
size_t m_line; size_t m_line;
size_t m_column; size_t m_column;
const char* m_error; std::string m_error;
JsonStream& m_stream; JsonStream& m_stream;
}; };

View File

@ -61,8 +61,8 @@ LuaCallbacks LuaBindings::makeChatCallbacks(MainInterface* mainInterface, Univer
}); });
// just for SE compat - this shoulda been a utility callback :moyai: // just for SE compat - this shoulda been a utility callback :moyai:
callbacks.registerCallback("parseArguments", [](String const& args) -> LuaVariadic<Json> { callbacks.registerCallback("parseArguments", [](String const& args) {
return Json::parseSequence(args).toArray(); return Json::parseSequence(args);
}); });
callbacks.registerCallback("command", [mainInterface](String const& command) -> StringList { callbacks.registerCallback("command", [mainInterface](String const& command) -> StringList {

View File

@ -9,14 +9,9 @@ PlayerTech::PlayerTech() {}
PlayerTech::PlayerTech(Json const& json) { PlayerTech::PlayerTech(Json const& json) {
m_availableTechs = jsonToStringSet(json.get("availableTechs")); m_availableTechs = jsonToStringSet(json.get("availableTechs"));
m_enabledTechs = jsonToStringSet(json.get("enabledTechs")); m_enabledTechs = jsonToStringSet(json.get("enabledTechs"));
auto techDatabase = Root::singleton().techDatabase(); m_equippedTechs = jsonToMapKV<HashMap<TechType, String>>(json.get("equippedTechs"), [](Json t) {
for (auto& p : json.getObject("equippedTechs")) { return TechTypeNames.getLeft(t.toString());
String techName = p.second.toString(); }, mem_fn(&Json::toString));
if (techDatabase->contains(techName))
m_equippedTechs.set(TechTypeNames.getLeft(p.first), techName);
else
Logger::warn("Unequipping unknown tech '{}' from slot '{}'", techName, p.first);
}
} }
Json PlayerTech::toJson() const { Json PlayerTech::toJson() const {