void PolycodeProjectEditor::saveFile() {

	if(!associatedProject) {
		return;
	}

	associatedProject->data.frameRate = atoi(framerateInput->getText().c_str());
	associatedProject->data.defaultWidth = atoi(defaultWidthInput->getText().c_str());
	associatedProject->data.defaultHeight = atoi(defaultHeightInput->getText().c_str());	
	associatedProject->data.entryPoint = entryPointInput->getText();
	
	associatedProject->data.backgroundColorR = bgColorBox->getSelectedColor().r;
	associatedProject->data.backgroundColorG = bgColorBox->getSelectedColor().g;
	associatedProject->data.backgroundColorB = bgColorBox->getSelectedColor().b;		

	associatedProject->data.modules.clear();
	
	for(int j=0; j < moduleCheckboxes.size(); j++) {
		if(moduleCheckboxes[j]->isChecked()) {
			associatedProject->data.modules.push_back(moduleCheckboxes[j]->getCaptionLabel());
		}
	}
	
	associatedProject->data.fonts.clear();	

	for(int j=0; j < fontEntries.size(); j++) {
		ProjectFontData fontData = ProjectFontData(fontEntries[j]->fontNameInput->getText(), fontEntries[j]->fontPath);
		associatedProject->data.fonts.push_back(fontData);
	}
		
	unsigned int afMap[6] = {0,1,2,4,8,16};
	unsigned int aaMap[4] = {0,2,4,6};
	String filteringMap[2] = {"nearest", "linear"};
		
	associatedProject->data.filteringMode = filteringMap[texFilteringComboBox->getSelectedIndex()];				
	associatedProject->data.aaLevel = aaMap[aaLevelComboBox->getSelectedIndex()];
	associatedProject->data.anisotropy = afMap[afLevelComboBox->getSelectedIndex()];
	associatedProject->data.vSync = vSyncCheckBox->isChecked();
	
	associatedProject->saveFile();
	setHasChanges(false);
}
Exemple #2
0
bool PolycodeProject::loadProjectFromFile() {

    if(!configFile.loadFromXML(projectFile)) {
        return false;
    }

    if(!configFile.root.readString("entryPoint", &(data.entryPoint))) {
        data.entryPoint = "Source/Main.lua";
        configFile.root.addChild("entryPoint", "Source/Main.lua");
    }

    if(!configFile.root.readInt("defaultWidth", &(data.defaultWidth))) {
        data.defaultWidth = 640;
        configFile.root.addChild("defaultWidth", 640);
    }

    if(!configFile.root.readInt("defaultHeight", &(data.defaultHeight))) {
        data.defaultHeight = 480;
        configFile.root.addChild("defaultHeight", 480);
    }

    if(!configFile.root.readString("textureFiltering", &(data.filteringMode))) {
        data.filteringMode = "linear";
        configFile.root.addChild("textureFiltering", String("linear"));
    }


    if(!configFile.root.readBool("vSync", &(data.vSync))) {
        data.vSync = false;
        configFile.root.addChild("vSync", false);
    }


    if(!configFile.root.readInt("antiAliasingLevel", &(data.aaLevel))) {
        data.aaLevel = 0;
        configFile.root.addChild("antiAliasingLevel", 0);
    }


    if(!configFile.root.readInt("anisotropyLevel", &(data.anisotropy))) {
        data.anisotropy = 0;
        configFile.root.addChild("anisotropyLevel", 0);
    }

    if(!configFile.root.readInt("frameRate", &(data.frameRate))) {
        data.frameRate = 60;
        configFile.root.addChild("frameRate", 60);
    }

    data.modules.clear();
    if(configFile.root["modules"]) {
        for(int i=0; i < configFile.root["modules"]->length; i++) {
            ObjectEntry *module = (*configFile.root["modules"])[i];

            if(module->type != ObjectEntry::STRING_ENTRY) continue;

            data.modules.push_back(module->stringVal);
            CoreServices::getInstance()->getResourceManager()->addArchive("Standalone/Modules/"+module->stringVal+"/API");

        }
    }

    data.fonts.clear();
    if(configFile.root["fonts"]) {
        for(int i=0; i < configFile.root["fonts"]->length; i++) {
            ObjectEntry *font = (*configFile.root["fonts"])[i];

            String fontName, fontPath;
            if(font->readString("name", &fontName) && font->readString("path", &fontPath)) {
                ProjectFontData fontData = ProjectFontData(fontName, fontPath);
                data.fonts.push_back(fontData);
            }
        }
    }

    if(configFile.root["backgroundColor"]) {
        ObjectEntry *color = configFile.root["backgroundColor"];

        bool haveAllColors = 1;
        haveAllColors &= color->readNumber("red", &(data.backgroundColorR));
        haveAllColors &= color->readNumber("green", &(data.backgroundColorG));
        haveAllColors &= color->readNumber("blue", &(data.backgroundColorB));

        if(!haveAllColors) {
            data.backgroundColorR = 0.0;
            data.backgroundColorG = 0.0;
            data.backgroundColorB = 0.0;

            if(!color) color = configFile.root.addChild("backgroundColor");
            color->addChild("red", 0.0);
            color->addChild("green", 0.0);
            color->addChild("blue", 0.0);
        }
    }

    return true;
}
bool PolycodeProject::loadProjectFromFile() {

	if(!configFile.loadFromXML(projectFile)) {
		return false;
	}
	
	if(configFile.root["entryPoint"]) {	
		data.entryPoint = configFile.root["entryPoint"]->stringVal;
	} else {
		data.entryPoint = "Source/Main.lua";
		configFile.root.addChild("entryPoint", "Source/Main.lua");
	}
	
	if(configFile.root["defaultWidth"]) {	
		data.defaultWidth = configFile.root["defaultWidth"]->intVal;
	} else {
		data.defaultWidth = 640;	
		configFile.root.addChild("defaultWidth", 640);			
	}
	
	if(configFile.root["defaultHeight"]) {	
		data.defaultHeight = configFile.root["defaultHeight"]->intVal;
	} else {
		data.defaultHeight = 480;	
		configFile.root.addChild("defaultHeight", 480);		
	}

	if(configFile.root["vSync"]) {	
		data.vSync = configFile.root["vSync"]->boolVal;
	} else {
		data.vSync = false;
		configFile.root.addChild("vSync", false);		
	}


	if(configFile.root["antiAliasingLevel"]) {
		data.aaLevel = configFile.root["antiAliasingLevel"]->intVal;
	} else {
		data.aaLevel = 0;
		configFile.root.addChild("antiAliasingLevel", 0);		
	}


	if(configFile.root["anisotropyLevel"]) {
		data.anisotropy = configFile.root["anisotropyLevel"]->intVal;
	} else {
		data.anisotropy = 0;
		configFile.root.addChild("anisotropyLevel", 0);		
	}

	if(configFile.root["frameRate"]) {
		data.frameRate = configFile.root["frameRate"]->intVal;	
	} else {
		data.frameRate = 60;
		configFile.root.addChild("frameRate", 60);
	}
	
	data.modules.clear();
	if(configFile.root["modules"]) {
		for(int i=0; i < configFile.root["modules"]->length; i++) {
			ObjectEntry *module = (*configFile.root["modules"])[i];
			data.modules.push_back(module->stringVal);
			CoreServices::getInstance()->getResourceManager()->addArchive("Standalone/Modules/"+module->stringVal+"/API");
			
		}
	}
	
	data.fonts.clear();
	if(configFile.root["fonts"]) {
		for(int i=0; i < configFile.root["fonts"]->length; i++) {
			ObjectEntry *font = (*configFile.root["fonts"])[i];
			ObjectEntry *fontName = (*font)["name"];
			ObjectEntry *fontPath = (*font)["path"];
			
			if(fontName && fontPath) {
				ProjectFontData fontData = ProjectFontData(fontName->stringVal, fontPath->stringVal);
				data.fonts.push_back(fontData);
			}
		}
	}		

	if(configFile.root["backgroundColor"]) {
		ObjectEntry *color = configFile.root["backgroundColor"];
		if((*color)["red"] && (*color)["green"] && (*color)["blue"]) {
			data.backgroundColorR = (*color)["red"]->NumberVal;
			data.backgroundColorG = (*color)["green"]->NumberVal;
			data.backgroundColorB = (*color)["blue"]->NumberVal;
		} else {
			data.backgroundColorR = 0.0;
			data.backgroundColorG = 0.0;
			data.backgroundColorB = 0.0;
			
			ObjectEntry *color = configFile.root.addChild("backgroundColor");			
			color->addChild("red", 0.0);
			color->addChild("green", 0.0);
			color->addChild("blue", 0.0);						
		}
	}

	return true;
}