|
|
@@ -25,17 +25,17 @@ namespace QGears
|
|
|
{
|
|
|
namespace FF7
|
|
|
{
|
|
|
- class FF7FiledModelsAndAnimationMetadata : public XmlFile
|
|
|
+ class FF7Metadata : public XmlFile
|
|
|
{
|
|
|
public:
|
|
|
- FF7FiledModelsAndAnimationMetadata(Ogre::String file)
|
|
|
+ FF7Metadata(Ogre::String file)
|
|
|
: XmlFile(file)
|
|
|
{
|
|
|
TiXmlNode* node = m_File.RootElement();
|
|
|
|
|
|
if (node == nullptr || node->ValueStr() != "metadata")
|
|
|
{
|
|
|
- throw std::runtime_error("FF7FiledModelsAndAnimationMetadata: " + m_File.ValueStr() + " is not a valid metadata file! No <metadata> in root.");
|
|
|
+ throw std::runtime_error("FF7Metadata: " + m_File.ValueStr() + " is not a valid metadata file! No <metadata> in root.");
|
|
|
}
|
|
|
|
|
|
node = node->FirstChild();
|
|
|
@@ -49,6 +49,11 @@ namespace QGears
|
|
|
{
|
|
|
ReadAnimations(node->FirstChild());
|
|
|
}
|
|
|
+ else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "scripts")
|
|
|
+ {
|
|
|
+ ReadScripts(node->FirstChild());
|
|
|
+ }
|
|
|
+
|
|
|
node = node->NextSibling();
|
|
|
}
|
|
|
}
|
|
|
@@ -112,9 +117,139 @@ namespace QGears
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void ReadScripts(TiXmlNode* node)
|
|
|
+ {
|
|
|
+ while (node)
|
|
|
+ {
|
|
|
+ if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "CharacterIds")
|
|
|
+ {
|
|
|
+ ReadCharacterIds(node->FirstChild());
|
|
|
+ }
|
|
|
+ else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "var_names")
|
|
|
+ {
|
|
|
+ ReadVarNames(node->FirstChild());
|
|
|
+ }
|
|
|
+ else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_names")
|
|
|
+ {
|
|
|
+ ReadEntityNames(node->FirstChild());
|
|
|
+ }
|
|
|
+ else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "field")
|
|
|
+ {
|
|
|
+ const auto name = GetString(node, "name");
|
|
|
+ ReadField(node->FirstChild(), name);
|
|
|
+ }
|
|
|
+ node = node->NextSibling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void ReadField(TiXmlNode* node, const std::string& name)
|
|
|
+ {
|
|
|
+ while (node)
|
|
|
+ {
|
|
|
+ if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "function")
|
|
|
+ {
|
|
|
+ ReadFunction(node, name);
|
|
|
+ }
|
|
|
+ else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity")
|
|
|
+ {
|
|
|
+ const auto oldName = GetString(node, "name");
|
|
|
+ const auto newName = GetString(node, "new");
|
|
|
+ mFieldData[name].mEntityNameMap[oldName] = newName;
|
|
|
+ }
|
|
|
+ node = node->NextSibling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void ReadFunction(TiXmlNode* node, const std::string& fieldName)
|
|
|
+ {
|
|
|
+ const auto entityName = GetString(node, "entity_name");
|
|
|
+ const auto oldFuncName = GetString(node, "name");
|
|
|
+ const auto newFuncName = GetString(node, "new");
|
|
|
+ const auto funcComment = GetString(node, "Comment");
|
|
|
+ mFieldData[fieldName].mFunctionMap[entityName][oldFuncName] = std::make_pair(newFuncName, funcComment);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void ReadEntityNames(TiXmlNode* node)
|
|
|
+ {
|
|
|
+ while (node)
|
|
|
+ {
|
|
|
+ if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity")
|
|
|
+ {
|
|
|
+ const auto oldName = GetString(node, "name");
|
|
|
+ const auto newName = GetString(node, "new");
|
|
|
+ mEntityNameMap[oldName] = newName;
|
|
|
+ }
|
|
|
+ node = node->NextSibling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void ReadVarNames(TiXmlNode* node)
|
|
|
+ {
|
|
|
+ while (node)
|
|
|
+ {
|
|
|
+ if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "var")
|
|
|
+ {
|
|
|
+ const auto bank = GetInt(node, "Bank");
|
|
|
+ const auto address = GetInt(node, "Address");
|
|
|
+ const auto name = GetString(node, "Name");
|
|
|
+ mVarMap[bank][address] = name;
|
|
|
+ }
|
|
|
+ node = node->NextSibling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void ReadCharacterIds(TiXmlNode* node)
|
|
|
+ {
|
|
|
+ while (node)
|
|
|
+ {
|
|
|
+ if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "char")
|
|
|
+ {
|
|
|
+ const auto id = GetInt(node, "Id");
|
|
|
+ const auto name = GetString(node, "Name");
|
|
|
+ mCharacterIds[id] = name;
|
|
|
+ node = node->NextSibling();
|
|
|
+ }
|
|
|
+ node = node->NextSibling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::pair<String,String> FieldScriptFunctionData(const String& fieldName, const String& entityName, const String& oldFunctionName)
|
|
|
+ {
|
|
|
+ // Find a collection of field data for this field
|
|
|
+ auto fieldIt = mFieldData.find(fieldName);
|
|
|
+ if (fieldIt != std::end(mFieldData))
|
|
|
+ {
|
|
|
+ // See if there is any info for this entity
|
|
|
+ auto entityIt = fieldIt->second.mFunctionMap.find(entityName);
|
|
|
+ if (entityIt != std::end(fieldIt->second.mFunctionMap))
|
|
|
+ {
|
|
|
+ // See if there is any info for this function in this entity
|
|
|
+ auto functionIt = entityIt->second.find(oldFunctionName);
|
|
|
+ if (functionIt != std::end(entityIt->second))
|
|
|
+ {
|
|
|
+ return functionIt->second;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return std::make_pair("", "");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
typedef std::map<String, String> LookupMap;
|
|
|
LookupMap mModels;
|
|
|
LookupMap mAnimations;
|
|
|
+ std::map<int, String> mCharacterIds;
|
|
|
+ std::map<int, std::map<int, String>> mVarMap;
|
|
|
+ LookupMap mEntityNameMap;
|
|
|
+
|
|
|
+ struct FieldMetaData
|
|
|
+ {
|
|
|
+ std::map<String, std::map<String, std::pair<String,String>>> mFunctionMap; // entity name to old function name finds new function name and comment
|
|
|
+ LookupMap mEntityNameMap; // old name finds new name
|
|
|
+ };
|
|
|
+ std::map<String, FieldMetaData> mFieldData;
|
|
|
+ friend class NameLookup;
|
|
|
};
|
|
|
|
|
|
class NameLookup
|
|
|
@@ -132,9 +267,51 @@ namespace QGears
|
|
|
return Data().Model(key);
|
|
|
}
|
|
|
|
|
|
- static FF7FiledModelsAndAnimationMetadata& Data()
|
|
|
+ static String FieldScriptVarName(int bank, int addr)
|
|
|
+ {
|
|
|
+ auto bankIt = Data().mVarMap.find(bank);
|
|
|
+ if (bankIt != std::end(Data().mVarMap))
|
|
|
+ {
|
|
|
+ auto addrIt = bankIt->second.find(addr);
|
|
|
+ if (addrIt != std::end(bankIt->second))
|
|
|
+ {
|
|
|
+ if (addrIt->second.empty() == false)
|
|
|
+ {
|
|
|
+ return addrIt->second;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ static String FieldScriptEntityName(const String& oldEntityName)
|
|
|
+ {
|
|
|
+ auto it = Data().mEntityNameMap.find(oldEntityName);
|
|
|
+ if (it != std::end(Data().mEntityNameMap))
|
|
|
+ {
|
|
|
+ return it->second;
|
|
|
+ }
|
|
|
+ return oldEntityName;
|
|
|
+ }
|
|
|
+
|
|
|
+ static String FieldScriptFunctionComment(const String& fieldName, const String& entityName, const String& oldFunctionName)
|
|
|
+ {
|
|
|
+ return Data().FieldScriptFunctionData(fieldName, entityName, oldFunctionName).second;
|
|
|
+ }
|
|
|
+
|
|
|
+ static String FieldScriptFunctionName(const String& fieldName, const String& entityName, const String& oldFunctionName)
|
|
|
+ {
|
|
|
+ auto name = Data().FieldScriptFunctionData(fieldName, entityName, oldFunctionName).first;
|
|
|
+ if (name.empty())
|
|
|
+ {
|
|
|
+ return oldFunctionName;
|
|
|
+ }
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ static FF7Metadata& Data()
|
|
|
{
|
|
|
- static FF7FiledModelsAndAnimationMetadata data("field_models_and_animation_metadata.xml");
|
|
|
+ static FF7Metadata data("field_models_and_animation_metadata.xml");
|
|
|
return data;
|
|
|
}
|
|
|
};
|