public bool ImportMission(string path) { MissionRoot root = GetMissionData(path); if (root == null) { return(false); } // Replace current mission with the imported mission mission = root; try { selectedVariantIndex = -1; selectedDifficultyIndex = -1; } catch (System.IndexOutOfRangeException ex) { Debug.LogException(ex); mission = new MissionRoot(); return(false); } // Import successful. Inform listeners. onChangedValuesCB?.Invoke(this); return(true); }
// Returns the SDK version specified in the .OPM file. Otherwise, returns null public static string GetSDKVersion(MissionData missionData) { string missionPath = Path.Combine(GetCachePath(), missionData.missionID.ToString()); // DLL or OPM string dllName = missionData.fileNames.FirstOrDefault((filename) => filename.IndexOf(".dll", System.StringComparison.OrdinalIgnoreCase) >= 0); string opmName = missionData.fileNames.FirstOrDefault((filename) => filename.IndexOf(".opm", System.StringComparison.OrdinalIgnoreCase) >= 0); bool isStandardMission = string.IsNullOrEmpty(dllName) && !string.IsNullOrEmpty(opmName); if (isStandardMission) { // Get the SDK version from the mission file try { string filePath = Path.Combine(missionPath, opmName); MissionRoot root = MissionReader.GetMissionData(filePath); return(root.sdkVersion); } catch (System.Exception ex) { Debug.LogError(ex); } } return(null); }
public void CreateNew() { Dispose(); map = new Map(); mission = new MissionRoot(); onChangedValuesCB?.Invoke(this); }
public bool LoadMission(string path) { // Load mission MissionRoot missionRoot = GetMissionData(path); if (missionRoot == null) { return(false); } // Load map using (ResourceManager resourceManager = new ResourceManager(UserPrefs.gameDirectory)) { using (Stream mapStream = resourceManager.GetResourceStream(missionRoot.levelDetails.mapName, true)) { if (mapStream == null) { return(false); } Map tempMap = Map.ReadMap(mapStream); if (tempMap == null) { return(false); } // Replace current mission with the loaded mission Dispose(); mission = missionRoot; map = tempMap; } } try { selectedVariantIndex = -1; selectedDifficultyIndex = -1; } catch (System.IndexOutOfRangeException ex) { Debug.LogException(ex); return(false); } // Inform listeners onChangedValuesCB?.Invoke(this); return(true); }
private Map LoadMap(MissionRoot mission) { // Load map using (ResourceManager resourceManager = new ResourceManager(".")) { using (Stream mapStream = resourceManager.GetResourceStream(mission.levelDetails.mapName, true)) { if (mapStream == null) { return(null); } return(Map.ReadMap(mapStream)); } } }
private MissionRoot LoadMission(string path) { MissionRoot missionRoot = null; // Load mission try { missionRoot = MissionReader.GetMissionData(path); } catch (System.Exception ex) { Debug.LogException(ex); } return(missionRoot); }
// Gets the final mission variant to use for the current game private static MissionVariant GetCombinedDifficultyVariant(MissionRoot root, int missionVariantIndex) { // Combine master variant with specified variant. The master variant is always used as a base. MissionVariant missionVariant = root.masterVariant; if (root.missionVariants.Count > 0) { missionVariant = MissionVariant.Concat(root.masterVariant, root.missionVariants[missionVariantIndex]); } // Startup Flags bool isMultiplayer = (int)root.levelDetails.missionType <= -4 && (int)root.levelDetails.missionType >= -8; int localDifficulty = SceneParameters.Players[SceneParameters.LocalPlayerID].Difficulty; // Combine master gaia resources with difficulty gaia resources if (!isMultiplayer && localDifficulty < missionVariant.tethysDifficulties.Count) { missionVariant.tethysGame = GameData.Concat(missionVariant.tethysGame, missionVariant.tethysDifficulties[localDifficulty]); } foreach (PlayerData data in missionVariant.players) { int difficulty = 0; SceneParameters.Player player = SceneParameters.Players.FirstOrDefault((scenePlayer) => scenePlayer.PlayerID == data.id); // Get difficulty if (player != null) { difficulty = player.Difficulty; } // If playing single player, all players get assigned the local player's difficulty if (!isMultiplayer && data.id != SceneParameters.LocalPlayerID) { difficulty = localDifficulty; } // Add difficulty resources if (difficulty < data.difficulties.Count) { data.resources = PlayerData.ResourceData.Concat(data.resources, data.difficulties[difficulty]); } } return(missionVariant); }
//[SerializeField] private MapRenderer _MapRenderer = default; private void Awake() { // Stop menu music MusicPlayer.StopMusic(); // Load mission MissionRoot mission = LoadMission(SceneParameters.MissionPath); if (mission == null) { InfoPopup.Create("Failed to load mission.", OnLoadFailed); return; } // Load map Map map = LoadMap(mission); if (mission == null) { InfoPopup.Create("Failed to load map.", OnLoadFailed); return; } // Load game state string error; if (!GameState.Initialize(mission, SceneParameters.RandomSeed, out error)) { InfoPopup.Create(error, OnLoadFailed); return; } // Setup Game //SetDaylightEverywhere(tethysGame.daylightEverywhere); //SetDaylightMoves(tethysGame.daylightMoves); //SetInitialLightLevel(tethysGame.initialLightLevel); // Initialize map //_MapRenderer.Initialize(mission, map, OnLoadMapComplete); }
private void LoadMissions() { _MissionListBox.Clear(); // Read missions in "ColonyGames" directory if (!Directory.Exists("ColonyGames")) { return; } // Add missions to list box foreach (string file in Directory.EnumerateFiles("ColonyGames", "*.opm", SearchOption.AllDirectories)) { try { MissionRoot mission = MissionReader.GetMissionData(file); _MissionListBox.AddItem(mission.levelDetails.description, new ListBoxItemContents(file, mission)); } catch (System.Exception ex) { Debug.LogException(ex); } } }
public static bool Initialize(MissionRoot mission, int randomSeed, out string error) { string techTreeName = mission.levelDetails.techTreeName; // Read info sheets Dictionary <map_id, GlobalStructureInfo> buildingInfo = SheetReader.ReadBuildingSheet(); Dictionary <map_id, GlobalVehicleInfo> vehicleInfo = SheetReader.ReadVehicleSheet(); Dictionary <map_id, GlobalWeaponInfo> weaponInfo = SheetReader.ReadWeaponSheet(); Dictionary <map_id, GlobalUnitInfo> starshipInfo = SheetReader.ReadStarshipSheet(); Dictionary <MineInfoKey, GlobalMineInfo> mineInfo = SheetReader.ReadMineSheet(); GlobalMoraleInfo moraleInfo = SheetReader.ReadMoraleSheet(); Dictionary <int, GlobalTechInfo> techInfo = TechSheetReader.ReadTechSheet(techTreeName); if (buildingInfo == null || vehicleInfo == null || weaponInfo == null || starshipInfo == null || mineInfo == null || moraleInfo == null || techInfo == null) { error = "Failed to load sheets."; return(false); } StructureInfo = new ReadOnlyDictionary <map_id, GlobalStructureInfo>(buildingInfo); VehicleInfo = new ReadOnlyDictionary <map_id, GlobalVehicleInfo>(vehicleInfo); WeaponInfo = new ReadOnlyDictionary <map_id, GlobalWeaponInfo>(weaponInfo); StarshipInfo = new ReadOnlyDictionary <map_id, GlobalUnitInfo>(starshipInfo); MineInfo = new ReadOnlyDictionary <MineInfoKey, GlobalMineInfo>(mineInfo); MoraleInfo = moraleInfo; TechInfo = new ReadOnlyDictionary <int, GlobalTechInfo>(techInfo); // Initialize core _Random = new System.Random(randomSeed); // Select mission variant (random) int missionVariantIndex = GetRandom(0, mission.missionVariants.Count); // Combine master variant with selected variant. The master variant is always used as a base. MissionVariant missionVariant = GetCombinedDifficultyVariant(mission, missionVariantIndex); //GameData tethysGame = missionVariant.tethysGame; bool isMultiplayer = (int)mission.levelDetails.missionType <= -4 && (int)mission.levelDetails.missionType >= -8; // Initialize players Player[] players = new Player[missionVariant.players.Count]; for (int i = 0; i < missionVariant.players.Count; ++i) { int playerId = missionVariant.players[i].id; // Find the player details for this slot SceneParameters.Player playerDetails = SceneParameters.Players.FirstOrDefault((scenePlayer) => scenePlayer.PlayerID == playerId); if (playerDetails != null) { // Create player int difficulty = playerDetails.Difficulty; players[playerId] = new Player(playerId, difficulty, missionVariant.players[i]); } else if (!isMultiplayer) { // For non-multiplayer games: If there aren't any player details for this slot, use the local player difficulty. SceneParameters.Player localPlayerDetails = SceneParameters.Players.FirstOrDefault((scenePlayer) => scenePlayer.PlayerID == SceneParameters.LocalPlayerID); int difficulty = localPlayerDetails.Difficulty; players[playerId] = new Player(playerId, difficulty, missionVariant.players[i]); } } Players = new ReadOnlyCollection <Player>(players); error = null; return(true); }
public void OnClick_Install() { // Get the cached mission details string json = File.ReadAllText(CachePath.GetMissionDetailsFilePath(missionData.missionID)); MissionData localData = JsonUtility.FromJson <MissionData>(json); string sdkVersion = CachePath.GetSDKVersion(localData); // Do not allow installation if mission files already exist foreach (string fileName in localData.fileNames) { string filePath = Path.Combine(UserPrefs.gameDirectory, fileName); if (File.Exists(filePath)) { InfoDialog.Create("Installation Failed", "The file '" + fileName + "' already exists in your game directory. Please remove it to continue."); return; } } List <string> installedFiles = new List <string>(); // Need to export plugin for standard mission OPM file if (m_IsStandardMission) { string opmFileName = localData.fileNames.FirstOrDefault((string fileName) => Path.GetExtension(fileName).ToLowerInvariant().Contains("opm")); string opmFilePath = Path.Combine(CachePath.GetMissionDirectory(localData.missionID), opmFileName); string pluginFileName = Path.ChangeExtension(opmFileName, ".dll"); string pluginPath = Path.Combine(UserPrefs.gameDirectory, pluginFileName); // Don't allow install if the plugin will overwrite another DLL of the same name if (File.Exists(pluginPath)) { InfoDialog.Create("Install Failed", "There is already a plugin named " + pluginFileName); return; } // Export plugin MissionRoot root = MissionReader.GetMissionData(opmFilePath); PluginExporter.ExportPlugin(pluginPath, root.sdkVersion, root.levelDetails); FileReference.AddReference(pluginFileName); installedFiles.Add(pluginFileName); } // Install mission from cache into game folder foreach (string fileName in localData.fileNames) { string filePath = Path.Combine(CachePath.GetMissionDirectory(localData.missionID), fileName); InstallFile(fileName, filePath); installedFiles.Add(fileName); } // Install SDK if (!string.IsNullOrEmpty(sdkVersion)) { InstallFile(CachePath.GetSDKFileName(sdkVersion), CachePath.GetSDKFilePath(sdkVersion)); InstallFile(CachePath.DotNetInteropFileName, CachePath.GetInteropFilePath(), true); installedFiles.Add(CachePath.GetSDKFileName(sdkVersion)); installedFiles.Add(CachePath.DotNetInteropFileName); } // Write installed files to cache using (FileStream fs = new FileStream(CachePath.GetMissionInstalledMetaFilePath(localData.missionID), FileMode.Create, FileAccess.Write, FileShare.Read)) using (StreamWriter writer = new StreamWriter(fs)) { foreach (string fileName in installedFiles) { writer.WriteLine(fileName); } } // Set buttons m_BtnInstall.gameObject.SetActive(false); m_BtnUninstall.gameObject.SetActive(true); m_BtnDelete.interactable = false; }
public ListBoxItemContents(string filePath, MissionRoot missionData) { MissionFilePath = filePath; MissionData = missionData; }