void Localization::LoadJSONFile(const QString& name) { ResourceCache* cache = context_->resourceCache(); JSONFile* jsonFile = cache->GetResource<JSONFile>(name); if (jsonFile) LoadJSON(jsonFile->GetRoot()); }
void Localization::LoadJSONFile(const String& name) { ResourceCache* cache = GetSubsystem<ResourceCache>(); JSONFile* jsonFile = cache->GetResource<JSONFile>(name); if (jsonFile) LoadJSON(jsonFile->GetRoot()); }
void JSBModule::Load(const String &moduleJSONFilename) { ResourceCache* cache = JSBind::context_->GetSubsystem<ResourceCache>(); JSONFile* moduleJSONFile = cache->GetResource<JSONFile>(moduleJSONFilename); if (!moduleJSONFile) { LOGERRORF("Couldn't load module json: %s", moduleJSONFilename.CString()); ErrorExit("Couldn't load module json"); } JSONValue moduleJSON = moduleJSONFile->GetRoot(); JSONValue sources = moduleJSON.GetChild("sources"); JSONValue classes = moduleJSON.GetChild("classes"); JSONValue includes = moduleJSON.GetChild("includes"); JSONValue classes_rename = moduleJSON.GetChild("classes_rename"); JSONValue overloads = moduleJSON.GetChild("overloads"); JSONValue requires = moduleJSON.GetChild("requires"); HashMap<String, String> rename; if (requires.IsArray()) { for (unsigned j = 0; j < requires.GetSize(); j++) { requirements_.Push(requires.GetString(j)); } } if (classes_rename.IsObject()) { Vector<String> childNames = classes_rename.GetValueNames(); for (unsigned j = 0; j < childNames.Size(); j++) { String classname = childNames.At(j); String crename = classes_rename.GetString(classname); rename[classname] = crename; } } if (includes.IsArray()) { for (unsigned j = 0; j < includes.GetSize(); j++) { includes_.Push(includes.GetString(j)); } } if (classes.IsArray()) { for (unsigned j = 0; j < classes.GetSize(); j++) { String classname = classes.GetString(j); if (rename.Contains(classname)) bindings_->RegisterClass(classname, rename[classname]); else bindings_->RegisterClass(classname); } } if (overloads.IsObject()) { Vector<String> childNames = overloads.GetChildNames(); for (unsigned j = 0; j < childNames.Size(); j++) { String classname = childNames.At(j); JSBClass* klass = bindings_->GetClass(classname); if (!klass) { ErrorExit("Bad overload klass"); } JSONValue classoverloads = overloads.GetChild(classname); Vector<String> functionNames = classoverloads.GetChildNames(); for (unsigned k = 0; k < functionNames.Size(); k++) { JSONValue sig = classoverloads.GetChild(functionNames[k]); if (!sig.IsArray()) { ErrorExit("Bad overload defintion"); } Vector<String> values; for (unsigned x = 0; x < sig.GetSize(); x++) { values.Push(sig.GetString(x)); } JSBFunctionOverride* fo = new JSBFunctionOverride(functionNames[k], values); klass->AddFunctionOverride(fo); } } } this->name_ = moduleJSON.GetString("name"); if (this->name_ == "Graphics") { #ifdef _MSC_VER sources.AddString("Graphics/Direct3D9"); #else sources.AddString("Graphics/OpenGL"); #endif } for (unsigned j = 0; j < sources.GetSize(); j++) { String sourceFolder = sources.GetString(j); Vector<String> fileNames; String sourceRoot = "Atomic"; if (sourceFolder == "Javascript") sourceRoot = "AtomicJS"; JSBind::fileSystem_->ScanDir(fileNames, JSBind::ROOT_FOLDER + "/Source/" + sourceRoot + "/" + sourceFolder, "*.h", SCAN_FILES, false); for (unsigned k = 0; k < fileNames.Size(); k++) { // TODO: filter String filepath = JSBind::ROOT_FOLDER + "/Source/" + sourceRoot + "/" + sourceFolder + "/" + fileNames[k]; this->headerFiles_.Push(filepath); } } }
void SceneStore::loadStore(Json::Value inValue) { try { JSONFile parsedScene; sceneFile = inValue["sceneFile"].asString(); bool readSuccess = parsedScene.readFile(sceneFile); if(readSuccess) { Json::Value sceneValue = parsedScene.getValue(); Json::Value entitiesValue = sceneValue["Entities"]; for(int i = 0; i < entitiesValue.size(); i++) { Json::Value entityValue = entitiesValue[i]; Entity * ent = new Entity(); addEntity(ent); ent->vanityName = entityValue["Name"].asString(); Json::Value componentValue = entityValue["Components"]; if(componentValue.isMember("window")) { WindowComponent* win = (new WindowComponent())->construct(componentValue["window"]); delete mainWindow; mainWindow = win; ent->addComponent(win); } if(componentValue.isMember("renderScreen")) { RenderScreenComponent* render = (new RenderScreenComponent())->construct(componentValue["renderScreen"]); ent->addComponent(render); } if(componentValue.isMember("render2d")) { Render2DComponent* render = (new Render2DComponent())->construct(componentValue["render2d"]); ent->addComponent(render); } if(componentValue.isMember("render3d")) { Render3DComponent* render = (new Render3DComponent())->construct(componentValue["render3d"]); ent->addComponent(render); } if(componentValue.isMember("terrain")) { TerrainComponent* terrain = (new TerrainComponent())->construct(componentValue["terrain"]); ent->addComponent(terrain); } if(componentValue.isMember("renderSkybox")) { RenderSkyboxComponent* render = (new RenderSkyboxComponent())->construct(componentValue["renderSkybox"]); ent->addComponent(render); } if(componentValue.isMember("world")) { WorldComponent* world = (new WorldComponent())->construct(componentValue["world"]); ent->addComponent(world); } if(componentValue.isMember("player")) { PlayerComponent* player = (new PlayerComponent())->construct(componentValue["player"]); ent->addComponent(player); } if(componentValue.isMember("physics")) { PhysicsComponent* physics = (new PhysicsComponent())->construct(componentValue["physics"]); ent->addComponent(physics); } if(componentValue.isMember("camera2d")) { Camera2DComponent* camera = (new Camera2DComponent())->construct(componentValue["camera2d"]); ent->addComponent(camera); } if(componentValue.isMember("camera3d")) { Camera3DComponent* camera = (new Camera3DComponent())->construct(componentValue["camera3d"]); ent->addComponent(camera); } if(componentValue.isMember("control")) { PlayerControlComponent* control = (new PlayerControlComponent())->construct(componentValue["control"]); ent->addComponent(control); } if(componentValue.isMember("directionalLight")) { DirectionalLightComponent* directionalLight = (new DirectionalLightComponent())->construct(componentValue["directionalLight"]); ent->addComponent(directionalLight); } if(componentValue.isMember("pointLight")) { PointLightComponent* pointLight = (new PointLightComponent())->construct(componentValue["pointLight"]); ent->addComponent(pointLight); } if(componentValue.isMember("spotLight")) { SpotLightComponent* spotLight = (new SpotLightComponent())->construct(componentValue["spotLight"]); ent->addComponent(spotLight); } if(componentValue.isMember("mouseRot")) { MouseRotationComponent* mouseRotComp = (new MouseRotationComponent())->construct(componentValue["mouseRot"]); ent->addComponent(mouseRotComp); } if(componentValue.isMember("childOf")) { /*std::string entityName = sceneBlock->getCurrentValue<std::string>(0); for(std::unordered_map<EntityID, Entity*>::iterator entityPair = entities.begin(); entityPair != entities.end(); ++entityPair) { Entity* checkEnt = entityPair->second; if(checkEnt->vanityName.compare(entityName) == 0) { checkEnt->addChild(ent); } }*/ } } correctlyLoaded = true; } } catch(std::exception& e) { Logger()<<"Scene "<<sceneFile<<" failed to load. "<<e.what()<<std::endl; } }