void HexagonGame::setLevelData(LevelData mLevelSettings, bool mMusicFirstPlay) { levelData = mLevelSettings; styleData = getStyleData(levelData.getStyleId()); musicData = getMusicData(levelData.getMusicId()); musicData.setFirstPlay(mMusicFirstPlay); }
void loadLevelData(const string& mPath) { for(auto filePath : getScan<Mode::Single, Type::File, Pick::ByExt>(mPath + "Levels/", ".json")) { Json::Value root{getRootFromFile(filePath)}; string luaScriptPath{mPath + "Scripts/" + root["lua_file"].asString()}; LevelData levelData{loadLevelFromJson(root)}; levelData.setPackPath(mPath); levelData.setLevelRootPath(filePath); levelData.setStyleRootPath(getStyleData(levelData.getStyleId()).getRootPath()); levelData.setLuaScriptPath(luaScriptPath); levelDataMap.insert(make_pair(levelData.getId(), levelData)); levelIdsByPackMap[levelData.getPackPath()].push_back(levelData.getId()); } }
void HexagonGame::executeEvents(Json::Value& mRoot, float mTime) { for (Json::Value& eventRoot : mRoot) { if(eventRoot["time"].asFloat() > mTime) continue; if(eventRoot["executed"].asBool()) continue; eventRoot["executed"] = true; string type{eventRoot["type"].asString()}; float duration{eventRoot["duration"].asFloat()}; string valueName{eventRoot["value_name"].asString()}; float value{eventRoot["value"].asFloat()}; string message{eventRoot["message"].asString()}; string id{eventRoot["id"].asString()}; if (type == "level_change") changeLevel(id); else if (type == "menu") goToMenu(); else if (type == "message_add") { if(getShowMessages()) addMessage(message, duration); } else if (type == "message_clear") clearMessages(); else if (type == "time_stop") timeStop = duration; else if (type == "timeline_wait") timeline.add(new Wait(duration)); else if (type == "timeline_clear") clearAndResetTimeline(timeline); else if (type == "value_float_set") levelData.setValueFloat(valueName, value); else if (type == "value_float_add") levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) + value); else if (type == "value_float_subtract") levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) - value); else if (type == "value_float_multiply") levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) * value); else if (type == "value_float_divide") levelData.setValueFloat(valueName, levelData.getValueFloat(valueName) / value); else if (type == "value_int_set") levelData.setValueInt(valueName, value); else if (type == "value_int_add") levelData.setValueInt(valueName, levelData.getValueFloat(valueName) + value); else if (type == "value_int_subtract") levelData.setValueInt(valueName, levelData.getValueFloat(valueName) - value); else if (type == "value_int_multiply") levelData.setValueInt(valueName, levelData.getValueFloat(valueName) * value); else if (type == "value_int_divide") levelData.setValueInt(valueName, levelData.getValueFloat(valueName) / value); else if (type == "music_set") { if(getChangeMusic()) { stopLevelMusic(); musicData = getMusicData(id); musicData.playRandomSegment(musicPtr); } } else if (type == "music_set_segment") { if(getChangeMusic()) { stopLevelMusic(); musicData = getMusicData(id); musicData.playSegment(musicPtr, eventRoot["segment_index"].asInt()); } } else if (type == "music_set_seconds") { if(getChangeMusic()) { stopLevelMusic(); musicData = getMusicData(id); musicData.playSeconds(musicPtr, eventRoot["seconds"].asInt()); } } else if (type == "style_set") { if(getChangeStyles()) styleData = getStyleData(id); } else if (type == "side_changing_stop") randomSideChangesEnabled = false; else if (type == "side_changing_start") randomSideChangesEnabled = true; else if (type == "increment_stop") incrementEnabled = false; else if (type == "increment_start") incrementEnabled = true; else if (type == "pulse_max_set") maxPulse = value; else if (type == "pulse_min_set") minPulse = value; else if (type == "pulse_speed_set") pulseSpeed = value; else if (type == "pulse_speed_b_set") pulseSpeedBackwards = value; else if (type == "script_exec") scripts.push_back(getScriptData(id, this)); else if (type == "script_queue") queueScript(getScriptData(id, this)); else log("unknown script command: " + type); } }