diff --git a/source/main/scripting/bindings/GenericFileFormatAngelscript.cpp b/source/main/scripting/bindings/GenericFileFormatAngelscript.cpp index 60bd9735e7..162abdde16 100644 --- a/source/main/scripting/bindings/GenericFileFormatAngelscript.cpp +++ b/source/main/scripting/bindings/GenericFileFormatAngelscript.cpp @@ -48,7 +48,8 @@ void RoR::RegisterGenericFileFormat(asIScriptEngine* engine) engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_LINEBREAK", (int)TokenType::LINEBREAK); engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_COMMENT", (int)TokenType::COMMENT); engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_STRING", (int)TokenType::STRING); - engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_NUMBER", (int)TokenType::NUMBER); + engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_FLOAT", (int)TokenType::FLOAT); + engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_INT", (int)TokenType::INT); engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_BOOL", (int)TokenType::BOOL); engine->RegisterEnumValue("TokenType", "TOKEN_TYPE_KEYWORD", (int)TokenType::KEYWORD); @@ -89,12 +90,14 @@ void RoR::RegisterGenericFileFormat(asIScriptEngine* engine) engine->RegisterObjectMethod("GenericDocContextClass", "string getTokString(int offset = 0)", asMETHOD(GenericDocContext, getTokString), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "float getTokFloat(int offset = 0)", asMETHOD(GenericDocContext, getTokFloat), asCALL_THISCALL); + engine->RegisterObjectMethod("GenericDocContextClass", "int getTokInt(int offset = 0)", asMETHOD(GenericDocContext, getTokInt), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool getTokBool(int offset = 0)", asMETHOD(GenericDocContext, getTokBool), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "string getTokKeyword(int offset = 0)", asMETHOD(GenericDocContext, getTokKeyword), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "string getTokComment(int offset = 0)", asMETHOD(GenericDocContext, getTokComment), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool isTokString(int offset = 0)", asMETHOD(GenericDocContext, isTokString), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool isTokFloat(int offset = 0)", asMETHOD(GenericDocContext, isTokFloat), asCALL_THISCALL); + engine->RegisterObjectMethod("GenericDocContextClass", "bool isTokInt(int offset = 0)", asMETHOD(GenericDocContext, isTokInt), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool isTokBool(int offset = 0)", asMETHOD(GenericDocContext, isTokBool), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool isTokKeyword(int offset = 0)", asMETHOD(GenericDocContext, isTokKeyword), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool isTokComment(int offset = 0)", asMETHOD(GenericDocContext, isTokComment), asCALL_THISCALL); @@ -105,6 +108,7 @@ void RoR::RegisterGenericFileFormat(asIScriptEngine* engine) engine->RegisterObjectMethod("GenericDocContextClass", "bool setTokString(int offset, const string &in)", asMETHOD(GenericDocContext, setTokString), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool setTokFloat(int offset, float)", asMETHOD(GenericDocContext, setTokFloat), asCALL_THISCALL); + engine->RegisterObjectMethod("GenericDocContextClass", "bool setTokInt(int offset, int)", asMETHOD(GenericDocContext, setTokInt), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool setTokBool(int offset, bool)", asMETHOD(GenericDocContext, setTokBool), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool setTokKeyword(int offset, const string &in)", asMETHOD(GenericDocContext, setTokKeyword), asCALL_THISCALL); engine->RegisterObjectMethod("GenericDocContextClass", "bool setTokComment(int offset, const string &in)", asMETHOD(GenericDocContext, setTokComment), asCALL_THISCALL); diff --git a/source/main/utils/GenericFileFormat.cpp b/source/main/utils/GenericFileFormat.cpp index 898e959ad8..91a41e21df 100644 --- a/source/main/utils/GenericFileFormat.cpp +++ b/source/main/utils/GenericFileFormat.cpp @@ -916,7 +916,14 @@ void DocumentParser::FlushStringishToken(RoR::TokenType type) void DocumentParser::FlushNumericToken() { tok.push_back('\0'); - doc.tokens.push_back({ TokenType::NUMBER, (float)Ogre::StringConverter::parseReal(tok.data()) }); + if (partial_tok_type == PartialToken::NUMBER_INTEGER) + { + doc.tokens.push_back({ TokenType::INT, (float)Ogre::StringConverter::parseInt(tok.data()) }); + } + else + { + doc.tokens.push_back({ TokenType::FLOAT, (float)Ogre::StringConverter::parseReal(tok.data()) }); + } tok.clear(); partial_tok_type = PartialToken::NONE; } @@ -1057,13 +1064,20 @@ void GenericDocument::saveToDataStream(Ogre::DataStreamPtr datastream) separator = ","; break; - case TokenType::NUMBER: + case TokenType::FLOAT: datastream->write(separator.data(), separator.size()); snprintf(buf, BUF_MAX, "%f", tok.data); datastream->write(buf, strlen(buf)); separator = ","; break; + case TokenType::INT: + datastream->write(separator.data(), separator.size()); + snprintf(buf, BUF_MAX, "%d", (int)tok.data); + datastream->write(buf, strlen(buf)); + separator = ","; + break; + case TokenType::BOOL: datastream->write(separator.data(), separator.size()); snprintf(buf, BUF_MAX, "%s", tok.data == 1.f ? "true" : "false"); diff --git a/source/main/utils/GenericFileFormat.h b/source/main/utils/GenericFileFormat.h index 375a6dcb8d..91e552cd17 100644 --- a/source/main/utils/GenericFileFormat.h +++ b/source/main/utils/GenericFileFormat.h @@ -51,7 +51,8 @@ enum class TokenType LINEBREAK, // Input: LF (CR is ignored); Output: platform-specific. COMMENT, // Line starting with ; (skipping whitespace). Data: offset in string pool. STRING, // Quoted string. Data: offset in string pool. - NUMBER, // Float. + FLOAT, + INT, BOOL, // Lowercase 'true'/'false'. Data: 1.0 for true, 0.0 for false. KEYWORD, // Unquoted string at start of line (skipping whitespace). Data: offset in string pool. }; @@ -113,12 +114,14 @@ struct GenericDocContext: public RefCountingObject std::string getTokString(int offset = 0) const { ROR_ASSERT(isTokString(offset)); return getStringData(offset); } float getTokFloat(int offset = 0) const { ROR_ASSERT(isTokFloat(offset)); return getFloatData(offset); } + int getTokInt(int offset = 0) const { ROR_ASSERT(isTokInt(offset)); return (int)getFloatData(offset); } bool getTokBool(int offset = 0) const { ROR_ASSERT(isTokBool(offset)); return getFloatData(offset) == 1.f; } std::string getTokKeyword(int offset = 0) const { ROR_ASSERT(isTokKeyword(offset)); return getStringData(offset); } std::string getTokComment(int offset = 0) const { ROR_ASSERT(isTokComment(offset)); return getStringData(offset); } bool isTokString(int offset = 0) const { return tokenType(offset) == TokenType::STRING; } - bool isTokFloat(int offset = 0) const { return tokenType(offset) == TokenType::NUMBER; } + bool isTokFloat(int offset = 0) const { return tokenType(offset) == TokenType::FLOAT; } + bool isTokInt(int offset = 0) const { return tokenType(offset) == TokenType::INT; } bool isTokBool(int offset = 0) const { return tokenType(offset) == TokenType::BOOL; } bool isTokKeyword(int offset = 0) const { return tokenType(offset) == TokenType::KEYWORD; } bool isTokComment(int offset = 0) const { return tokenType(offset) == TokenType::COMMENT; } @@ -130,7 +133,8 @@ struct GenericDocContext: public RefCountingObject bool eraseToken(int offset = 0); //!< @return false if offset is beyond EOF bool setTokString(int offset, const std::string& str) { return setStringData(offset, TokenType::STRING, str); } - bool setTokFloat(int offset, float val) { return setFloatData(offset, TokenType::NUMBER, val); } + bool setTokFloat(int offset, float val) { return setFloatData(offset, TokenType::FLOAT, val); } + bool setTokInt(int offset, int val) { return setFloatData(offset, TokenType::INT, val); } bool setTokBool(int offset, bool val) { return setFloatData(offset, TokenType::BOOL, val); } bool setTokKeyword(int offset, const std::string& str) { return setStringData(offset, TokenType::KEYWORD, str); } bool setTokComment(int offset, const std::string& str) { return setStringData(offset, TokenType::COMMENT, str); }