mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 11:54:00 +02:00
- added initial folder(s) and code to handle loading common data to save duplicated files space
This commit is contained in:
@@ -398,22 +398,22 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
|
|||||||
//image
|
//image
|
||||||
const XmlNode *imageNode= parametersNode->getChild("image");
|
const XmlNode *imageNode= parametersNode->getChild("image");
|
||||||
image= Renderer::getInstance().newTexture2D(rsGame);
|
image= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
|
image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||||
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
|
loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||||
|
|
||||||
//image cancel
|
//image cancel
|
||||||
const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel");
|
const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel");
|
||||||
cancelImage= Renderer::getInstance().newTexture2D(rsGame);
|
cancelImage= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue());
|
cancelImage->load(imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||||
loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++;
|
loadedFileList[imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||||
|
|
||||||
//meeting point
|
//meeting point
|
||||||
const XmlNode *meetingPointNode= parametersNode->getChild("meeting-point");
|
const XmlNode *meetingPointNode= parametersNode->getChild("meeting-point");
|
||||||
meetingPoint= meetingPointNode->getAttribute("value")->getBoolValue();
|
meetingPoint= meetingPointNode->getAttribute("value")->getBoolValue();
|
||||||
if(meetingPoint){
|
if(meetingPoint){
|
||||||
meetingPointImage= Renderer::getInstance().newTexture2D(rsGame);
|
meetingPointImage= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
meetingPointImage->load(currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue());
|
meetingPointImage->load(meetingPointNode->getAttribute("image-path")->getRestrictedValue(currentPath));
|
||||||
loadedFileList[currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue()]++;
|
loadedFileList[meetingPointNode->getAttribute("image-path")->getRestrictedValue(currentPath)]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//selection sounds
|
//selection sounds
|
||||||
@@ -422,10 +422,10 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
|
|||||||
selectionSounds.resize(selectionSoundNode->getChildCount());
|
selectionSounds.resize(selectionSoundNode->getChildCount());
|
||||||
for(int i=0; i<selectionSounds.getSounds().size(); ++i){
|
for(int i=0; i<selectionSounds.getSounds().size(); ++i){
|
||||||
const XmlNode *soundNode= selectionSoundNode->getChild("sound", i);
|
const XmlNode *soundNode= selectionSoundNode->getChild("sound", i);
|
||||||
string path= soundNode->getAttribute("path")->getRestrictedValue();
|
string path= soundNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||||
StaticSound *sound= new StaticSound();
|
StaticSound *sound= new StaticSound();
|
||||||
sound->load(currentPath + path);
|
sound->load(path);
|
||||||
loadedFileList[currentPath + path]++;
|
loadedFileList[path]++;
|
||||||
selectionSounds[i]= sound;
|
selectionSounds[i]= sound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,10 +436,10 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
|
|||||||
commandSounds.resize(commandSoundNode->getChildCount());
|
commandSounds.resize(commandSoundNode->getChildCount());
|
||||||
for(int i=0; i<commandSoundNode->getChildCount(); ++i){
|
for(int i=0; i<commandSoundNode->getChildCount(); ++i){
|
||||||
const XmlNode *soundNode= commandSoundNode->getChild("sound", i);
|
const XmlNode *soundNode= commandSoundNode->getChild("sound", i);
|
||||||
string path= soundNode->getAttribute("path")->getRestrictedValue();
|
string path= soundNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||||
StaticSound *sound= new StaticSound();
|
StaticSound *sound= new StaticSound();
|
||||||
sound->load(currentPath + path);
|
sound->load(path);
|
||||||
loadedFileList[currentPath + path]++;
|
loadedFileList[path]++;
|
||||||
commandSounds[i]= sound;
|
commandSounds[i]= sound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -131,6 +131,8 @@ class XmlAttribute{
|
|||||||
private:
|
private:
|
||||||
string value;
|
string value;
|
||||||
string name;
|
string name;
|
||||||
|
bool skipRestrictionCheck;
|
||||||
|
bool usesCommondata;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XmlAttribute(XmlAttribute&);
|
XmlAttribute(XmlAttribute&);
|
||||||
@@ -141,15 +143,15 @@ public:
|
|||||||
XmlAttribute(const string &name, const string &value);
|
XmlAttribute(const string &name, const string &value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const string &getName() const {return name;}
|
const string getName() const {return name;}
|
||||||
const string &getValue() const {return value;}
|
const string getValue(string prefixValue="") const;
|
||||||
|
|
||||||
bool getBoolValue() const;
|
bool getBoolValue() const;
|
||||||
int getIntValue() const;
|
int getIntValue() const;
|
||||||
int getIntValue(int min, int max) const;
|
int getIntValue(int min, int max) const;
|
||||||
float getFloatValue() const;
|
float getFloatValue() const;
|
||||||
float getFloatValue(float min, float max) const;
|
float getFloatValue(float min, float max) const;
|
||||||
const string &getRestrictedValue() const;
|
const string getRestrictedValue(string prefixValue="") const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -106,7 +106,6 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
|
|||||||
|
|
||||||
bool Properties::applyTagsToValue(string &value) {
|
bool Properties::applyTagsToValue(string &value) {
|
||||||
string originalValue = value;
|
string originalValue = value;
|
||||||
|
|
||||||
char *homeDir = NULL;
|
char *homeDir = NULL;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
homeDir = getenv("USERPROFILE");
|
homeDir = getenv("USERPROFILE");
|
||||||
@@ -144,11 +143,19 @@ bool Properties::applyTagsToValue(string &value) {
|
|||||||
#if defined(CUSTOM_DATA_INSTALL_PATH)
|
#if defined(CUSTOM_DATA_INSTALL_PATH)
|
||||||
replaceAll(value, "$APPLICATIONDATAPATH", CUSTOM_DATA_INSTALL_PATH);
|
replaceAll(value, "$APPLICATIONDATAPATH", CUSTOM_DATA_INSTALL_PATH);
|
||||||
replaceAll(value, "%%APPLICATIONDATAPATH%%", CUSTOM_DATA_INSTALL_PATH);
|
replaceAll(value, "%%APPLICATIONDATAPATH%%", CUSTOM_DATA_INSTALL_PATH);
|
||||||
|
|
||||||
|
replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||||
|
replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||||
|
|
||||||
#else
|
#else
|
||||||
replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath);
|
replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath);
|
||||||
replaceAll(value, "%%APPLICATIONDATAPATH%%", Properties::applicationPath);
|
replaceAll(value, "%%APPLICATIONDATAPATH%%", Properties::applicationPath);
|
||||||
|
|
||||||
|
replaceAll(value, "$COMMONDATAPATH", Properties::applicationPath + "/commondata/");
|
||||||
|
replaceAll(value, "%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//printf("\nBEFORE SUBSTITUTE [%s] AFTER [%s]\n",originalValue.c_str(),value.c_str());
|
||||||
return (originalValue != value);
|
return (originalValue != value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "properties.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -181,7 +182,6 @@ XmlTree::~XmlTree(){
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
XmlNode::XmlNode(DOMNode *node) {
|
XmlNode::XmlNode(DOMNode *node) {
|
||||||
|
|
||||||
if(node == NULL || node->getNodeName() == NULL) {
|
if(node == NULL || node->getNodeName() == NULL) {
|
||||||
throw runtime_error("XML structure seems to be corrupt!");
|
throw runtime_error("XML structure seems to be corrupt!");
|
||||||
}
|
}
|
||||||
@@ -223,6 +223,7 @@ XmlNode::XmlNode(DOMNode *node){
|
|||||||
if(node->getNodeType() == DOMNode::ELEMENT_NODE && children.size() == 0) {
|
if(node->getNodeType() == DOMNode::ELEMENT_NODE && children.size() == 0) {
|
||||||
char *textStr= XMLString::transcode(node->getTextContent());
|
char *textStr= XMLString::transcode(node->getTextContent());
|
||||||
text= textStr;
|
text= textStr;
|
||||||
|
//Properties::applyTagsToValue(this->text);
|
||||||
XMLString::release(&textStr);
|
XMLString::release(&textStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,8 +262,9 @@ XmlAttribute *XmlNode::getAttribute(const string &name,bool mustExist) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
XmlNode *XmlNode::getChild(unsigned int i) const {
|
XmlNode *XmlNode::getChild(unsigned int i) const {
|
||||||
if(i>=children.size())
|
if(i >= children.size()) {
|
||||||
throw runtime_error("\"" + getName()+"\" node doesn't have "+intToStr(i+1)+" children");
|
throw runtime_error("\"" + getName()+"\" node doesn't have "+intToStr(i+1)+" children");
|
||||||
|
}
|
||||||
return children[i];
|
return children[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,13 +287,10 @@ XmlNode *XmlNode::getChild(const string &childName, unsigned int i) const{
|
|||||||
throw runtime_error("Node \""+getName()+"\" doesn't have "+intToStr(i+1)+" children named \""+childName+"\"\n\nTree: "+getTreeString());
|
throw runtime_error("Node \""+getName()+"\" doesn't have "+intToStr(i+1)+" children named \""+childName+"\"\n\nTree: "+getTreeString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlNode::hasChildAtIndex(const string &childName, int i) const
|
bool XmlNode::hasChildAtIndex(const string &childName, int i) const {
|
||||||
{
|
|
||||||
int count= 0;
|
int count= 0;
|
||||||
for(unsigned int j = 0; j < children.size(); ++j)
|
for(unsigned int j = 0; j < children.size(); ++j) {
|
||||||
{
|
if(children[j]->getName()==childName) {
|
||||||
if(children[j]->getName()==childName)
|
|
||||||
{
|
|
||||||
if(count == i) {
|
if(count == i) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -303,13 +302,10 @@ bool XmlNode::hasChildAtIndex(const string &childName, int i) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool XmlNode::hasChild(const string &childName) const
|
bool XmlNode::hasChild(const string &childName) const {
|
||||||
{
|
|
||||||
int count= 0;
|
int count= 0;
|
||||||
for(unsigned int j = 0; j < children.size(); ++j)
|
for(unsigned int j = 0; j < children.size(); ++j) {
|
||||||
{
|
if(children[j]->getName() == childName) {
|
||||||
if(children[j]->getName()==childName)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,18 +370,26 @@ string XmlNode::getTreeString() const{
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
XmlAttribute::XmlAttribute(DOMNode *attribute) {
|
XmlAttribute::XmlAttribute(DOMNode *attribute) {
|
||||||
char str[strSize];
|
skipRestrictionCheck = false;
|
||||||
|
usesCommondata = false;
|
||||||
|
char str[strSize]="";
|
||||||
|
|
||||||
XMLString::transcode(attribute->getNodeValue(), str, strSize-1);
|
XMLString::transcode(attribute->getNodeValue(), str, strSize-1);
|
||||||
value= str;
|
value= str;
|
||||||
|
usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos));
|
||||||
|
skipRestrictionCheck = Properties::applyTagsToValue(this->value);
|
||||||
|
|
||||||
XMLString::transcode(attribute->getNodeName(), str, strSize-1);
|
XMLString::transcode(attribute->getNodeName(), str, strSize-1);
|
||||||
name= str;
|
name= str;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlAttribute::XmlAttribute(const string &name, const string &value) {
|
XmlAttribute::XmlAttribute(const string &name, const string &value) {
|
||||||
|
skipRestrictionCheck = false;
|
||||||
|
usesCommondata = false;
|
||||||
this->name= name;
|
this->name= name;
|
||||||
this->value= value;
|
this->value= value;
|
||||||
|
usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos));
|
||||||
|
skipRestrictionCheck = Properties::applyTagsToValue(this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlAttribute::getBoolValue() const {
|
bool XmlAttribute::getBoolValue() const {
|
||||||
@@ -424,8 +428,16 @@ float XmlAttribute::getFloatValue(float min, float max) const{
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string &XmlAttribute::getRestrictedValue() const
|
const string XmlAttribute::getValue(string prefixValue) const {
|
||||||
{
|
string result = value;
|
||||||
|
if(skipRestrictionCheck == false && usesCommondata == false) {
|
||||||
|
result = prefixValue + value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string XmlAttribute::getRestrictedValue(string prefixValue) const {
|
||||||
|
if(skipRestrictionCheck == false && usesCommondata == false) {
|
||||||
const string allowedCharacters = "abcdefghijklmnopqrstuvwxyz1234567890._-/";
|
const string allowedCharacters = "abcdefghijklmnopqrstuvwxyz1234567890._-/";
|
||||||
|
|
||||||
for(unsigned int i= 0; i<value.size(); ++i){
|
for(unsigned int i= 0; i<value.size(); ++i){
|
||||||
@@ -435,8 +447,13 @@ const string &XmlAttribute::getRestrictedValue() const
|
|||||||
"\"\nFor portability reasons the only allowed characters in this field are: " + allowedCharacters);
|
"\"\nFor portability reasons the only allowed characters in this field are: " + allowedCharacters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
string result = value;
|
||||||
|
if(skipRestrictionCheck == false && usesCommondata == false) {
|
||||||
|
result = prefixValue + value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
Reference in New Issue
Block a user