New world and player files format
This commit is contained in:
+20
-16
@@ -320,8 +320,12 @@ void JObject::num(std::string key, uint& dst) const {
|
||||
|
||||
JObject* JObject::obj(std::string key) const {
|
||||
auto found = map.find(key);
|
||||
if (found != map.end())
|
||||
return found->second->value.obj;
|
||||
if (found != map.end()) {
|
||||
auto& val = found->second;
|
||||
if (val->type != valtype::object)
|
||||
return nullptr;
|
||||
return val->value.obj;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -500,6 +504,19 @@ JArray* Parser::parseArray() {
|
||||
Value* Parser::parseValue() {
|
||||
char next = peek();
|
||||
valvalue val;
|
||||
if (next == '-' || next == '+') {
|
||||
pos++;
|
||||
number_u num;
|
||||
valtype type;
|
||||
if (parseNumber(next == '-' ? -1 : 1, num)) {
|
||||
val.integer = num.ival;
|
||||
type = valtype::integer;
|
||||
} else {
|
||||
val.decimal = num.fval;
|
||||
type = valtype::number;
|
||||
}
|
||||
return new Value(type, val);
|
||||
}
|
||||
if (is_identifier_start(next)) {
|
||||
string literal = parseName();
|
||||
if (literal == "true") {
|
||||
@@ -515,7 +532,7 @@ Value* Parser::parseValue() {
|
||||
val.decimal = NAN;
|
||||
return new Value(valtype::number, val);
|
||||
}
|
||||
throw error("invalid literal");
|
||||
throw error("invalid literal ");
|
||||
}
|
||||
if (next == '{') {
|
||||
val.obj = parseObject();
|
||||
@@ -525,19 +542,6 @@ Value* Parser::parseValue() {
|
||||
val.arr = parseArray();
|
||||
return new Value(valtype::array, val);
|
||||
}
|
||||
if (next == '-' || next == '+') {
|
||||
pos++;
|
||||
number_u num;
|
||||
valtype type;
|
||||
if (parseNumber(next == '-' ? -1 : 1, num)) {
|
||||
val.integer = num.ival;
|
||||
type = valtype::integer;
|
||||
} else {
|
||||
val.decimal = num.fval;
|
||||
type = valtype::number;
|
||||
}
|
||||
return new Value(type, val);
|
||||
}
|
||||
if (is_digit(next)) {
|
||||
number_u num;
|
||||
valtype type;
|
||||
|
||||
Reference in New Issue
Block a user