public bool SerializeXmlAssets() { try { var gameTempPath = Path.Combine(ViewModelLocator.AssetsTabViewModel.AssetTempDirectory.FullName, Guid.NewGuid().ToString() + ".xml"); var gameSerializer = new GameSerializer(); gameSerializer.OutputPath = gameTempPath; gameSerializer.Serialize(Game); Asset.SelectedAsset.SafeFile = new FileInfo(gameTempPath); var setSerializer = new SetSerializer() { Game = Game }; foreach (SetModel set in ViewModelLocator.SetTabViewModel.Items) { var setTempPath = Path.Combine(ViewModelLocator.AssetsTabViewModel.AssetTempDirectory.FullName, Guid.NewGuid().ToString() + ".xml"); setSerializer.OutputPath = setTempPath; setSerializer.Serialize(set._set); set.Asset.SelectedAsset.SafeFile = new FileInfo(setTempPath); } var scriptSerializer = new GameScriptSerializer(Game.Id) { Game = Game }; foreach (ScriptItemModel script in ViewModelLocator.ScriptsTabViewModel.Scripts) { scriptSerializer.OutputPath = script.Asset.SafePath; scriptSerializer.Serialize(script._script); } var proxyTempPath = Path.Combine(ViewModelLocator.AssetsTabViewModel.AssetTempDirectory.FullName, Guid.NewGuid().ToString() + ".xml"); var proxySerializer = new ProxyGeneratorSerializer(Game.Id) { Game = Game }; proxySerializer.OutputPath = proxyTempPath; proxySerializer.Serialize(ViewModelLocator.ProxyTabViewModel._proxydef); ViewModelLocator.ProxyTabViewModel.Asset.SelectedAsset.SafeFile = new FileInfo(proxyTempPath); return(true); } catch { return(false); } }
public ScriptsTabViewModel() { GlobalVariables = new IdeCollection <IdeBaseItem>(); foreach (var globalvariable in ViewModelLocator.GameLoader.Game.GlobalVariables) { GlobalVariables.Add(new GlobalVariableItemModel(globalvariable.Value, GlobalVariables)); } GlobalVariables.CollectionChanged += (sender, args) => { ViewModelLocator.GameLoader.Game.GlobalVariables = GlobalVariables.ToDictionary( x => (x as GlobalVariableItemModel).Name, y => (y as GlobalVariableItemModel)._globalVariable ); }; AddGlobalVariableCommand = new RelayCommand(AddGlobalVariable); PlayerVariables = new IdeCollection <IdeBaseItem>(); foreach (var globalvariable in ViewModelLocator.GameLoader.Game.Player.GlobalVariables) { PlayerVariables.Add(new GlobalVariableItemModel(globalvariable.Value, PlayerVariables)); } PlayerVariables.CollectionChanged += (sender, args) => { ViewModelLocator.GameLoader.Game.Player.GlobalVariables = PlayerVariables.ToDictionary( x => (x as GlobalVariableItemModel).Name, y => (y as GlobalVariableItemModel)._globalVariable ); }; AddPlayerVariableCommand = new RelayCommand(AddPlayerVariable); Scripts = new IdeCollection <IdeBaseItem>(); var game = ViewModelLocator.GameLoader.Game; var scriptSerializer = new GameScriptSerializer(game.Id) { Game = game }; foreach (var scriptPath in game.Scripts) { var path = Path.Combine(ViewModelLocator.GameLoader.WorkingDirectory.FullName, scriptPath); var script = (GameScript)scriptSerializer.Deserialize(path); var scriptModel = new ScriptItemModel(script, Scripts); Scripts.Add(scriptModel); } Scripts.CollectionChanged += (a, b) => { // ViewModelLocator.GameLoader.Scripts = Scripts.Select(x => ((ScriptItemModel)x)._script); }; AddScriptCommand = new RelayCommand(AddScript); Events = new IdeCollection <IdeBaseItem>(); foreach (var gameEventType in ViewModelLocator.GameLoader.Game.Events) { foreach (var gameEvent in gameEventType.Value) { Events.Add(new GameEventItemModel(gameEvent, Events)); } } Events.CollectionChanged += (a, b) => { var items = ViewModelLocator.GameLoader.Game.Events = Events.GroupBy(x => ((GameEventItemModel)x).Name) .ToDictionary( x => x.Key, y => y.Select(z => ((GameEventItemModel)z)._gameEvent).ToArray()); }; AddEventCommand = new RelayCommand(AddGameEvent); }