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); }
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>(); foreach (var script in ViewModelLocator.GameLoader.Scripts) { Scripts.Add(new ScriptItemModel(script, Scripts)); } 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); }