- add support for models, sounds and images to be able to load from commondata
This commit is contained in:
parent
102363f151
commit
c3d1d6fca0
|
@ -949,7 +949,7 @@ void MainWindow::loadUnit(string path, string skillName) {
|
|||
foundSkillName = true;
|
||||
|
||||
if(sn->getChild("animation") != NULL) {
|
||||
skillModelFile = unitPath + '/' + sn->getChild("animation")->getAttribute("path")->getRestrictedValue();
|
||||
skillModelFile = sn->getChild("animation")->getAttribute("path")->getRestrictedValue(unitPath + '/');
|
||||
printf("Found skill model [%s]\n",skillModelFile.c_str());
|
||||
}
|
||||
|
||||
|
@ -962,7 +962,7 @@ void MainWindow::loadUnit(string path, string skillName) {
|
|||
const XmlNode *pf= particlesNode->getChild("particle-file");
|
||||
if(pf != NULL) {
|
||||
skillParticleFile = unitPath + '/' + pf->getAttribute("path")->getRestrictedValue();
|
||||
printf("Found skill skill particle [%s]\n",skillParticleFile.c_str());
|
||||
printf("Found skill particle [%s]\n",skillParticleFile.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,8 +57,8 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
|
|||
}
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
texture->load(currentPath + textureNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
texture->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
}
|
||||
else {
|
||||
texture= NULL;
|
||||
|
@ -68,18 +68,18 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
|
|||
if(particleSystemNode->hasChild("model")){
|
||||
const XmlNode *modelNode= particleSystemNode->getChild("model");
|
||||
bool modelEnabled= modelNode->getAttribute("value")->getBoolValue();
|
||||
if(modelEnabled){
|
||||
string path= modelNode->getAttribute("path")->getRestrictedValue();
|
||||
model= renderer->newModel(rsGame);
|
||||
|
||||
if(modelEnabled) {
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
|
||||
model->load(currentPath + path, false, &loadedFileList);
|
||||
loadedFileList[currentPath + path]++;
|
||||
string path= modelNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
model= renderer->newModel(rsGame);
|
||||
|
||||
model->load(path, false, &loadedFileList);
|
||||
loadedFileList[path]++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
model= NULL;
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
|
|||
alternations= alternatingNode->getAttribute("value")->getIntValue();
|
||||
}
|
||||
//mode
|
||||
if(particleSystemNode->hasChild("mode")){
|
||||
if(particleSystemNode->hasChild("mode")) {
|
||||
const XmlNode *modeNode= particleSystemNode->getChild("mode");
|
||||
mode= modeNode->getAttribute("value")->getRestrictedValue();
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ void CommandType::load(int id, const XmlNode *n, const string &dir,
|
|||
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
|
||||
//unit requirements
|
||||
const XmlNode *unitRequirementsNode= n->getChild("unit-requirements");
|
||||
|
@ -390,15 +390,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir,
|
|||
startSounds.resize(startSoundNode->getChildCount());
|
||||
for(int i=0; i<startSoundNode->getChildCount(); ++i){
|
||||
const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue();
|
||||
trimPathWithStartingSlash(path);
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath,true);
|
||||
|
||||
StaticSound *sound= new StaticSound();
|
||||
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
sound->load(currentPath + path);
|
||||
loadedFileList[currentPath + path]++;
|
||||
sound->load(path);
|
||||
loadedFileList[path]++;
|
||||
startSounds[i]= sound;
|
||||
}
|
||||
}
|
||||
|
@ -409,15 +408,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir,
|
|||
builtSounds.resize(builtSoundNode->getChildCount());
|
||||
for(int i=0; i<builtSoundNode->getChildCount(); ++i){
|
||||
const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue();
|
||||
trimPathWithStartingSlash(path);
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath,true);
|
||||
|
||||
StaticSound *sound= new StaticSound();
|
||||
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
sound->load(currentPath + path);
|
||||
loadedFileList[currentPath + path]++;
|
||||
sound->load(path);
|
||||
loadedFileList[path]++;
|
||||
builtSounds[i]= sound;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,8 +152,8 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
|
|||
bool value= musicNode->getAttribute("value")->getBoolValue();
|
||||
if(value) {
|
||||
music= new StrSound();
|
||||
music->open(currentPath + musicNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + musicNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
music->open(musicNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[musicNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
}
|
||||
}
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
|
|
@ -74,8 +74,8 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
|
|||
//image
|
||||
const XmlNode *imageNode= resourceNode->getChild("image");
|
||||
image= renderer.newTexture2D(rsGame);
|
||||
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
|
||||
//type
|
||||
const XmlNode *typeNode= resourceNode->getChild("type");
|
||||
|
@ -87,7 +87,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
|
|||
{
|
||||
//model
|
||||
const XmlNode *modelNode= typeNode->getChild("model");
|
||||
string modelPath= currentPath + modelNode->getAttribute("path")->getRestrictedValue();
|
||||
string modelPath= modelNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
|
||||
model= renderer.newModel(rsGame);
|
||||
model->load(modelPath, false, &loadedFileList);
|
||||
|
|
|
@ -62,12 +62,13 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
|||
animSpeed= sn->getChild("anim-speed")->getAttribute("value")->getIntValue();
|
||||
|
||||
//model
|
||||
string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue();
|
||||
animation= Renderer::getInstance().newModel(rsGame);
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
animation->load(currentPath + path, false, &loadedFileList);
|
||||
loadedFileList[currentPath + path]++;
|
||||
|
||||
string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
animation= Renderer::getInstance().newModel(rsGame);
|
||||
animation->load(path, false, &loadedFileList);
|
||||
loadedFileList[path]++;
|
||||
|
||||
//particles
|
||||
if(sn->hasChild("particles")) {
|
||||
|
@ -93,12 +94,11 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
|||
sounds.resize(soundNode->getChildCount());
|
||||
for(int i = 0; i < soundNode->getChildCount(); ++i) {
|
||||
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue();
|
||||
trimPathWithStartingSlash(path);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true);
|
||||
|
||||
StaticSound *sound= new StaticSound();
|
||||
sound->load(currentPath + path);
|
||||
loadedFileList[currentPath + path]++;
|
||||
sound->load(path);
|
||||
loadedFileList[path]++;
|
||||
sounds[i]= sound;
|
||||
}
|
||||
}
|
||||
|
@ -259,12 +259,11 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
|
|||
projSounds.resize(soundNode->getChildCount());
|
||||
for(int i=0; i<soundNode->getChildCount(); ++i){
|
||||
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue();
|
||||
trimPathWithStartingSlash(path);
|
||||
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true);
|
||||
|
||||
StaticSound *sound= new StaticSound();
|
||||
sound->load(currentPath + path);
|
||||
loadedFileList[currentPath + path]++;
|
||||
sound->load(path);
|
||||
loadedFileList[path]++;
|
||||
projSounds[i]= sound;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,14 +70,14 @@ void UpgradeType::load(const string &dir, const TechTree *techTree,
|
|||
//image
|
||||
const XmlNode *imageNode= upgradeNode->getChild("image");
|
||||
image= Renderer::getInstance().newTexture2D(rsGame);
|
||||
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
|
||||
//image cancel
|
||||
const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel");
|
||||
cancelImage= Renderer::getInstance().newTexture2D(rsGame);
|
||||
cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
cancelImage->load(imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
|
||||
//upgrade time
|
||||
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");
|
||||
|
|
|
@ -39,64 +39,76 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode,
|
|||
const XmlNode *dayNode= xmlNode->getChild("day-sound");
|
||||
enabledDay= dayNode->getAttribute("enabled")->getBoolValue();
|
||||
if(enabledDay) {
|
||||
path= dayNode->getAttribute("path")->getRestrictedValue();
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
day.open(currentPath + path);
|
||||
|
||||
path= dayNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
day.open(path);
|
||||
loadedFileList[path]++;
|
||||
|
||||
alwaysPlayDay= dayNode->getAttribute("play-always")->getBoolValue();
|
||||
}
|
||||
|
||||
//night
|
||||
const XmlNode *nightNode= xmlNode->getChild("night-sound");
|
||||
enabledNight= nightNode->getAttribute("enabled")->getBoolValue();
|
||||
if(enabledNight){
|
||||
path= nightNode->getAttribute("path")->getRestrictedValue();
|
||||
if(enabledNight) {
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
night.open(currentPath + path);
|
||||
|
||||
path= nightNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
night.open(path);
|
||||
loadedFileList[path]++;
|
||||
|
||||
alwaysPlayNight= nightNode->getAttribute("play-always")->getBoolValue();
|
||||
}
|
||||
|
||||
//rain
|
||||
const XmlNode *rainNode= xmlNode->getChild("rain-sound");
|
||||
enabledRain= rainNode->getAttribute("enabled")->getBoolValue();
|
||||
if(enabledRain){
|
||||
path= rainNode->getAttribute("path")->getRestrictedValue();
|
||||
if(enabledRain) {
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
rain.open(currentPath + path);
|
||||
|
||||
path= rainNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
rain.open(path);
|
||||
loadedFileList[path]++;
|
||||
}
|
||||
|
||||
//snow
|
||||
const XmlNode *snowNode= xmlNode->getChild("snow-sound");
|
||||
enabledSnow= snowNode->getAttribute("enabled")->getBoolValue();
|
||||
if(enabledSnow){
|
||||
path= snowNode->getAttribute("path")->getRestrictedValue();
|
||||
if(enabledSnow) {
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
snow.open(currentPath + path);
|
||||
|
||||
path= snowNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
snow.open(path);
|
||||
loadedFileList[path]++;
|
||||
}
|
||||
|
||||
//dayStart
|
||||
const XmlNode *dayStartNode= xmlNode->getChild("day-start-sound");
|
||||
enabledDayStart= dayStartNode->getAttribute("enabled")->getBoolValue();
|
||||
if(enabledDayStart){
|
||||
path= dayStartNode->getAttribute("path")->getRestrictedValue();
|
||||
if(enabledDayStart) {
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
dayStart.load(currentPath + path);
|
||||
loadedFileList[currentPath + path]++;
|
||||
|
||||
path= dayStartNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
dayStart.load(path);
|
||||
loadedFileList[path]++;
|
||||
}
|
||||
|
||||
//nightStart
|
||||
const XmlNode *nightStartNode= xmlNode->getChild("night-start-sound");
|
||||
enabledNightStart= nightStartNode->getAttribute("enabled")->getBoolValue();
|
||||
if(enabledNightStart){
|
||||
path= nightStartNode->getAttribute("path")->getRestrictedValue();
|
||||
if(enabledNightStart) {
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
nightStart.load(currentPath + path);
|
||||
loadedFileList[currentPath + path]++;
|
||||
|
||||
path= nightStartNode->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
nightStart.load(path);
|
||||
loadedFileList[path]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,8 +185,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||
for(int j=0; j<childCount; ++j){
|
||||
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
|
||||
surfPixmaps[i][j].init(3);
|
||||
surfPixmaps[i][j].load(currentPath + textureNode->getAttribute("path")->getRestrictedValue());
|
||||
loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
surfPixmaps[i][j].load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
|
||||
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
|
||||
}
|
||||
|
@ -201,8 +213,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||
for(int j=0; j<childCount; ++j) {
|
||||
const XmlNode *modelNode= objectNode->getChild("model", j);
|
||||
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
|
||||
objectTypes[i].loadModel(currentPath + pathAttribute->getRestrictedValue(),&loadedFileList);
|
||||
loadedFileList[currentPath + pathAttribute->getRestrictedValue()]++;
|
||||
objectTypes[i].loadModel(pathAttribute->getRestrictedValue(currentPath),&loadedFileList);
|
||||
loadedFileList[pathAttribute->getRestrictedValue(currentPath)]++;
|
||||
|
||||
if(modelNode->hasChild("particles")){
|
||||
const XmlNode *particleNode= modelNode->getChild("particles");
|
||||
|
@ -249,8 +261,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||
waterTex->getPixmap()->init(waterFrameCount, 4);
|
||||
for(int i=0; i<waterFrameCount; ++i){
|
||||
const XmlNode *waterFrameNode= waterNode->getChild("texture", i);
|
||||
waterTex->getPixmap()->loadSlice(currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue(), i);
|
||||
loadedFileList[currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue()]++;
|
||||
waterTex->getPixmap()->loadSlice(waterFrameNode->getAttribute("path")->getRestrictedValue(currentPath), i);
|
||||
loadedFileList[waterFrameNode->getAttribute("path")->getRestrictedValue(currentPath)]++;
|
||||
}
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
|
|
@ -144,14 +144,14 @@ public:
|
|||
|
||||
public:
|
||||
const string getName() const {return name;}
|
||||
const string getValue(string prefixValue="") const;
|
||||
const string getValue(string prefixValue="", bool trimValueWithStartingSlash=false) const;
|
||||
|
||||
bool getBoolValue() const;
|
||||
int getIntValue() const;
|
||||
int getIntValue(int min, int max) const;
|
||||
float getFloatValue() const;
|
||||
float getFloatValue(float min, float max) const;
|
||||
const string getRestrictedValue(string prefixValue="") const;
|
||||
const string getRestrictedValue(string prefixValue="", bool trimValueWithStartingSlash=false) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -21,14 +21,16 @@
|
|||
#include "util.h"
|
||||
#include "types.h"
|
||||
#include "properties.h"
|
||||
#include "platform_common.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::PlatformCommon;
|
||||
|
||||
namespace Shared{ namespace Xml{
|
||||
namespace Shared { namespace Xml {
|
||||
|
||||
using namespace Util;
|
||||
|
||||
|
@ -428,15 +430,18 @@ float XmlAttribute::getFloatValue(float min, float max) const{
|
|||
return f;
|
||||
}
|
||||
|
||||
const string XmlAttribute::getValue(string prefixValue) const {
|
||||
const string XmlAttribute::getValue(string prefixValue, bool trimValueWithStartingSlash) const {
|
||||
string result = value;
|
||||
if(skipRestrictionCheck == false && usesCommondata == false) {
|
||||
result = prefixValue + value;
|
||||
if(trimValueWithStartingSlash == true) {
|
||||
trimPathWithStartingSlash(result);
|
||||
}
|
||||
result = prefixValue + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const string XmlAttribute::getRestrictedValue(string prefixValue) const {
|
||||
const string XmlAttribute::getRestrictedValue(string prefixValue, bool trimValueWithStartingSlash) const {
|
||||
if(skipRestrictionCheck == false && usesCommondata == false) {
|
||||
const string allowedCharacters = "abcdefghijklmnopqrstuvwxyz1234567890._-/";
|
||||
|
||||
|
@ -451,7 +456,10 @@ const string XmlAttribute::getRestrictedValue(string prefixValue) const {
|
|||
|
||||
string result = value;
|
||||
if(skipRestrictionCheck == false && usesCommondata == false) {
|
||||
result = prefixValue + value;
|
||||
if(trimValueWithStartingSlash == true) {
|
||||
trimPathWithStartingSlash(result);
|
||||
}
|
||||
result = prefixValue + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user