00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "ScriptLoader.h"
00018 #include "Log.h"
00019 #include "FileStream.h"
00020 #include "Kernel.h"
00021
00022 namespace nrEngine{
00023
00024
00025 ScriptLoader::ScriptLoader() : IResourceLoader("ScriptLoader")
00026 {
00027 initializeResourceLoader();
00028 }
00029
00030
00031
00032 ScriptLoader::~ScriptLoader()
00033 {
00034
00035 }
00036
00037
00038 Result ScriptLoader::initializeResourceLoader()
00039 {
00040
00041 declareSupportedResourceType("Script");
00042 declareSupportedResourceType("Config");
00043 declareSupportedResourceType("nrScript");
00044
00045
00046 declareSupportedFileType("script");
00047 declareSupportedFileType("nrscript");
00048 declareSupportedFileType("cfg");
00049
00050
00051 declareTypeMap("nrscript", "nrScript");
00052 declareTypeMap("script", "nrScript");
00053 declareTypeMap("cfg", "Config");
00054
00055 return OK;
00056 }
00057
00058
00059 Result ScriptLoader::loadResource(IResource* res, const std::string& fileName, PropertyList* param)
00060 {
00061
00062 FileStream* fStream = new FileStream();
00063 Result ret = fStream->open(fileName);
00064 if (ret == OK){
00065
00066
00067 std::string str = fStream->getAsString();
00068
00069
00070 IScript* scr = dynamic_cast<IScript*>(res);
00071
00072
00073 ret = scr->loadFromString(str);
00074
00075 }
00076 delete fStream;
00077
00078
00079 return ret;
00080 }
00081
00082
00083
00084 IResource* ScriptLoader::createResource(const std::string& resourceType, PropertyList* params)
00085 {
00086
00087 if (resourceType == "Script" || resourceType == "nrScript")
00088 return new Script();
00089 else if (resourceType == "Config"){
00090
00091 Script* scr = new Script();
00092 scr->setRunStepwise(false);
00093 return scr;
00094 }
00095 return NULL;
00096 }
00097
00098
00099
00100 IResource* ScriptLoader::createEmptyResource(const std::string& resourceType)
00101 {
00102
00103 return new EmptyScript(resourceType);
00104 }
00105
00106
00107 };
00108