public override void Enter(object[] parameters) { if (ScreensManager.PreviousScreen.GetType() != typeof(WorldOptionsScreen)) { m_directoryName = (string)parameters[0]; m_worldSettings = (WorldSettings)parameters[1]; m_originalWorldSettingsData.Clear(); m_worldSettings.Save(m_originalWorldSettingsData, liveModifiableParametersOnly: true); } }
public static void ChangeWorld(string directoryName, WorldSettings worldSettings) { string path = Storage.CombinePaths(directoryName, "Project.xml"); if (!Storage.FileExists(path)) { return; } XElement xElement = null; using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read)) { xElement = XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true); } XElement gameInfoNode = GetGameInfoNode(xElement); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.ApplyOverrides(gameInfoNode); GameMode value = valuesDictionary.GetValue <GameMode>("GameMode"); worldSettings.Save(valuesDictionary, liveModifiableParametersOnly: true); gameInfoNode.RemoveNodes(); valuesDictionary.Save(gameInfoNode); using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xElement, stream2, null, throwOnError: true); } if (worldSettings.GameMode != value) { if (worldSettings.GameMode == GameMode.Adventure) { TakeWorldSnapshot(directoryName, "AdventureRestart"); } else { DeleteWorldSnapshot(directoryName, "AdventureRestart"); } } }
public static WorldInfo CreateWorld(WorldSettings worldSettings) { string unusedWorldDirectoryName = GetUnusedWorldDirectoryName(); Storage.CreateDirectory(unusedWorldDirectoryName); if (!ValidateWorldName(worldSettings.Name)) { throw new InvalidOperationException($"World name \"{worldSettings.Name}\" is invalid."); } int num; if (string.IsNullOrEmpty(worldSettings.Seed)) { num = (int)(long)(Time.RealTime * 1000.0); } else if (worldSettings.Seed == "0") { num = 0; } else { num = 0; int num2 = 1; string seed = worldSettings.Seed; foreach (char c in seed) { num += c * num2; num2 += 29; } } ValuesDictionary valuesDictionary = new ValuesDictionary(); worldSettings.Save(valuesDictionary, liveModifiableParametersOnly: false); valuesDictionary.SetValue("WorldDirectoryName", unusedWorldDirectoryName); valuesDictionary.SetValue("WorldSeed", num); ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary2.SetValue("Players", new ValuesDictionary()); DatabaseObject databaseObject = DatabaseManager.GameDatabase.Database.FindDatabaseObject("GameProject", DatabaseManager.GameDatabase.ProjectTemplateType, throwIfNotFound: true); XElement xElement = new XElement("Project"); XmlUtils.SetAttributeValue(xElement, "Guid", databaseObject.Guid); XmlUtils.SetAttributeValue(xElement, "Name", "GameProject"); XmlUtils.SetAttributeValue(xElement, "Version", VersionsManager.SerializationVersion); XElement xElement2 = new XElement("Subsystems"); xElement.Add(xElement2); XElement xElement3 = new XElement("Values"); XmlUtils.SetAttributeValue(xElement3, "Name", "GameInfo"); valuesDictionary.Save(xElement3); xElement2.Add(xElement3); XElement xElement4 = new XElement("Values"); XmlUtils.SetAttributeValue(xElement4, "Name", "Players"); valuesDictionary2.Save(xElement4); xElement2.Add(xElement4); using (Stream stream = Storage.OpenFile(Storage.CombinePaths(unusedWorldDirectoryName, "Project.xml"), OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xElement, stream, null, throwOnError: true); } return(GetWorldInfo(unusedWorldDirectoryName)); }
public override void Save(ValuesDictionary valuesDictionary) { WorldSettings.Save(valuesDictionary, liveModifiableParametersOnly: false); valuesDictionary.SetValue("WorldSeed", WorldSeed); valuesDictionary.SetValue("TotalElapsedGameTime", TotalElapsedGameTime); }
public override void Update() { if (m_gameModeButton.IsClicked && m_worldSettings.GameMode != GameMode.Cruel) { IList <int> enumValues = EnumUtils.GetEnumValues(typeof(GameMode)); do { m_worldSettings.GameMode = (GameMode)((enumValues.IndexOf((int)m_worldSettings.GameMode) + 1) % enumValues.Count); }while (m_worldSettings.GameMode == GameMode.Cruel); m_descriptionLabel.Text = StringsManager.GetString("GameMode." + m_worldSettings.GameMode.ToString() + ".Description"); } m_currentWorldSettingsData.Clear(); m_worldSettings.Save(m_currentWorldSettingsData, liveModifiableParametersOnly: true); bool flag = !CompareValueDictionaries(m_originalWorldSettingsData, m_currentWorldSettingsData); bool flag2 = WorldsManager.ValidateWorldName(m_worldSettings.Name); m_nameTextBox.Text = m_worldSettings.Name; m_seedLabel.Text = m_worldSettings.Seed; m_gameModeButton.Text = LanguageControl.Get("GameMode", m_worldSettings.GameMode.ToString()); m_gameModeButton.IsEnabled = (m_worldSettings.GameMode != GameMode.Cruel); m_errorLabel.IsVisible = !flag2; m_descriptionLabel.IsVisible = flag2; m_uploadButton.IsEnabled = (flag2 && !flag); m_applyButton.IsEnabled = (flag2 && flag); m_descriptionLabel.Text = StringsManager.GetString("GameMode." + m_worldSettings.GameMode.ToString() + ".Description"); if (m_worldOptionsButton.IsClicked) { ScreensManager.SwitchScreen("WorldOptions", m_worldSettings, true); } if (m_deleteButton.IsClicked) { MessageDialog dialog = null; dialog = new MessageDialog(LanguageControl.Get(fName, 1), LanguageControl.Get(fName, 2), LanguageControl.Get("Usual", "yes"), LanguageControl.Get("Usual", "no"), delegate(MessageDialogButton button) { if (button == MessageDialogButton.Button1) { WorldsManager.DeleteWorld(m_directoryName); ScreensManager.SwitchScreen("Play"); DialogsManager.HideDialog(dialog); } else { DialogsManager.HideDialog(dialog); } }); dialog.AutoHide = false; DialogsManager.ShowDialog(null, dialog); } if (m_uploadButton.IsClicked && flag2 && !flag) { ExternalContentManager.ShowUploadUi(ExternalContentType.World, m_directoryName); } if ((m_applyButton.IsClicked && flag2) & flag) { if (m_worldSettings.GameMode != 0 && m_worldSettings.GameMode != GameMode.Adventure) { m_worldSettings.ResetOptionsForNonCreativeMode(); } WorldsManager.ChangeWorld(m_directoryName, m_worldSettings); ScreensManager.SwitchScreen("Play"); } if (base.Input.Back || base.Input.Cancel || Children.Find <ButtonWidget>("TopBar.Back").IsClicked) { if (flag) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 3), LanguageControl.Get(fName, 4), LanguageControl.Get("Usual", "yes"), LanguageControl.Get("Usual", "no"), delegate(MessageDialogButton button) { if (button == MessageDialogButton.Button1) { ScreensManager.SwitchScreen("Play"); } })); } else { ScreensManager.SwitchScreen("Play"); } } }