public EventTabModel getSpecificEventList(Guid containerID) { EventTabModel container = eventList.SingleOrDefault( c => c.UniqueID == containerID); return(container); }
private void TestParseAllEvents() { //Arrange Script tester = new Script(); foreach (string file in Directory.EnumerateFiles("events", "*.txt")) { string contents = File.ReadAllText(file); //Act EventTabModel model = EventParser.CreateEventFromScript(file, contents); EventContainer container = new EventContainer(model); List <EventContainer> list = new List <EventContainer> { container }; Dictionary <string, string> files = EventParser.ParseAllEvents(list); string filecontent = files.FirstOrDefault().Value; string fileName = files.FirstOrDefault().Key; //Assert Assert.IsNotNull(model); Assert.IsTrue(model.EventList.Any()); Assert.IsNotNull(fileName); Assert.IsNotNull(filecontent); tester.Analyse(filecontent); Assert.IsFalse(tester.Logger.hasErrors()); } }
private void CopyElement(object obj) { UndoService.Current[GetUndoRoot()].BeginChangeSetBatch("CopyAnyFile", false); FileManager dialog = new FileManager(ModeType.Edit); if (obj is FocusGridModel) { FocusGridModel item = new FocusGridModel((FocusGridModel)obj); item.VisibleName += "_copy"; Project.fociList.Add(item); RaisePropertyChanged(() => Project.fociList); } else if (obj is LocalisationModel) { LocalisationModel item = new LocalisationModel((LocalisationModel)obj); item.VisibleName += "_copy"; Project.localisationList.Add(item); RaisePropertyChanged(() => Project.localisationList); } else if (obj is EventTabModel) { EventTabModel item = new EventTabModel((EventTabModel)obj); item.VisibleName += "_copy"; Project.eventList.Add(item); RaisePropertyChanged(() => Project.eventList); } else if (obj is ScriptModel) { ScriptModel item = new ScriptModel((ScriptModel)obj); item.VisibleName += "_copy"; Project.scriptList.Add(item); RaisePropertyChanged(() => Project.scriptList); } UndoService.Current[GetUndoRoot()].EndChangeSetBatch(); }
public void TestEventParser() { EventTabModel model = TestScriptToEvent(); TestEventToScript(model); TestParseAllEvents(); }
public EventContainer(EventTabModel item) { IdentifierID = item.UniqueID; ContainerID = item.VisibleName; EventNamespace = item.EventNamespace; FileInfo = item.FileInfo; EventList = new List <Event>(); foreach (EventModel model in item.EventList) { EventList.Add(new Event(model)); } }
private EventTabModel TestScriptToEvent() { //Arrange string eventScript = File.ReadAllText("Baltic.txt"); //Act EventTabModel model = EventParser.CreateEventFromScript("Baltic.txt", eventScript); //Assert Assert.IsNotNull(model); Assert.IsTrue(model.EventList.Any()); Assert.AreEqual(model.EventNamespace, "baltic"); Assert.AreEqual(model.VisibleName, "Baltic"); return(model); }
private void TestEventToScript(EventTabModel model) { //Arrange EventContainer container = new EventContainer(model); List <EventContainer> list = new List <EventContainer> { container }; //Act Dictionary <string, string> files = EventParser.ParseAllEvents(list); string filecontent = files.FirstOrDefault().Value; string fileName = files.FirstOrDefault().Key; //Assert Assert.IsNotNull(filecontent); Assert.IsNotNull(fileName); Assert.AreEqual(fileName, "Baltic"); }
public void SetFileType(object param) { File = null; ListViewItem item = param as ListViewItem; if (item == null) { return; } switch (item.Tag as string) { case "FocusTreeItem": File = new FocusGridModel("New file"); Messenger.Default.Send(new NotificationMessage(this, new ViewModelLocator().Tutorial, "NewFocusTreeFile")); break; case "LocalisationItem": File = new LocalisationModel("New file"); Messenger.Default.Send(new NotificationMessage(this, new ViewModelLocator().Tutorial, "NewLocalizationFile")); break; case "EventItem": File = new EventTabModel("New file"); Messenger.Default.Send(new NotificationMessage(this, new ViewModelLocator().Tutorial, "NewEventFile")); break; case "GenericItem": File = new ScriptModel("New file"); Messenger.Default.Send(new NotificationMessage(this, new ViewModelLocator().Tutorial, "NewScriptFile")); break; } }
private void EditElement(object obj) { UndoService.Current[GetUndoRoot()].BeginChangeSetBatch("EditAnyFile", false); FileManager dialog = new FileManager(ModeType.Edit); if (obj is FocusGridModel) { FocusGridModel item = (FocusGridModel)obj; new ViewModelLocator().FileManager.File = new FocusGridModel(item.VisibleName) { TAG = item.TAG, AdditionnalMods = item.AdditionnalMods }; dialog.ShowDialog(); if (new ViewModelLocator().FileManager.File == null) { return; } FocusGridModel newItem = new ViewModelLocator().FileManager.File as FocusGridModel; if (newItem == null) { return; } item.VisibleName = newItem.VisibleName; item.TAG = newItem.TAG; item.AdditionnalMods = newItem.AdditionnalMods; } else if (obj is LocalisationModel) { LocalisationModel item = (LocalisationModel)obj; new ViewModelLocator().FileManager.File = new LocalisationModel(item.VisibleName) { LanguageName = item.LanguageName }; dialog.ShowDialog(); if (new ViewModelLocator().FileManager.File == null) { return; } LocalisationModel newItem = new ViewModelLocator().FileManager.File as LocalisationModel; if (newItem == null) { return; } item.VisibleName = newItem.VisibleName; item.LanguageName = newItem.LanguageName; } else if (obj is EventTabModel) { EventTabModel item = (EventTabModel)obj; new ViewModelLocator().FileManager.File = new EventTabModel(item.VisibleName) { EventNamespace = item.EventNamespace }; dialog.ShowDialog(); if (new ViewModelLocator().FileManager.File == null) { return; } EventTabModel newItem = (new ViewModelLocator()).FileManager.File as EventTabModel; if (newItem == null) { return; } item.VisibleName = newItem.VisibleName; item.EventNamespace = newItem.EventNamespace; } else if (obj is ScriptModel) { ScriptModel item = (ScriptModel)obj; new ViewModelLocator().FileManager.File = new ScriptModel(item.VisibleName); dialog.ShowDialog(); if (new ViewModelLocator().FileManager.File == null) { return; } ScriptModel newItem = new ViewModelLocator().FileManager.File as ScriptModel; if (newItem != null) { item.VisibleName = newItem.VisibleName; } } UndoService.Current[GetUndoRoot()].EndChangeSetBatch(); }
public static string ParseEventForCompare(EventTabModel model) { EventContainer container = new EventContainer(model); return(Parse(container.EventList.ToList(), container.EventNamespace)); }
public static EventTabModel CreateEventFromScript(string fileName, Script script) { if (script.Logger.hasErrors()) { return(null); } EventTabModel container = new EventTabModel(Path.GetFileNameWithoutExtension(fileName)) { EventNamespace = script.FindValue("add_namespace").Parse() }; Dictionary <CodeBlock, Event.EventType> events = new Dictionary <CodeBlock, Event.EventType>(); foreach (Assignation codeStruct in script .FindAllAssignationsInRoot("country_event")) { if (!(codeStruct.Value is CodeBlock)) { continue; } CodeBlock block = (CodeBlock)codeStruct.Value; events[block] = Event.EventType.country_event; } foreach (Assignation codeStruct in script .FindAllAssignationsInRoot("news_event")) { if (!(codeStruct.Value is CodeBlock)) { continue; } CodeBlock block = (CodeBlock)codeStruct.Value; events[block] = Event.EventType.news_event; } foreach (KeyValuePair <CodeBlock, Event.EventType> pair in events) { CodeBlock block = pair.Key; //Check if the event is only a call, if it isn't, it must have a least one option if (block.FindAssignation("option") == null) { continue; } EventModel newEvent = new EventModel(); try { newEvent.Id = script.TryParse(block, "id"); newEvent.Type = pair.Value; //An event can have no picture. newEvent.Picture = script.TryParse(block, "picture", null, false)?.Replace("GFX_", ""); newEvent.IsMajor = block.FindValue("major") != null && YesToBool(script.TryParse(block, "major")); newEvent.IsHidden = block.FindValue("hidden") != null && YesToBool(script.TryParse(block, "hidden")); newEvent.IsTriggeredOnly = block.FindValue("is_triggered_only") != null && YesToBool(script.TryParse(block, "is_triggered_only")); newEvent.IsFiredOnce = block.FindValue("fire_only_once") != null && YesToBool(script.TryParse(block, "fire_only_once")); if (block.FindAllValuesOfType <CodeBlock>("desc").Any()) { foreach (ICodeStruct desc in block.FindAllValuesOfType <ICodeStruct>("desc")) { newEvent.Descriptions.Add(new EventDescriptionModel { InternalScript = desc.GetContentAsScript(new string[0], script.Comments) }); } } foreach (ICodeStruct option in block.FindAllValuesOfType <CodeBlock>("option")) { newEvent.Options.Add(new EventOptionModel { Name = script.TryParse(option, "name"), InternalScript = option.GetContentAsScript(new[] { "name" }, script.Comments) }); } //Get all core scripting elements Script InternalEventScript = block. GetContentAsScript(ALL_PARSED_ELEMENTS.ToArray(), script.Comments); newEvent.InternalScript = InternalEventScript; if (script.Logger.hasErrors()) { new ViewModelLocator().ErrorDawg.AddError( string.Join("\n", script.Logger.getErrors())); continue; } container.EventList.Add(newEvent); } catch (Exception) { //TODO: Add language support new ViewModelLocator().ErrorDawg.AddError(script.Logger.ErrorsToString()); new ViewModelLocator().ErrorDawg.AddError("Invalid syntax for event " + block.FindValue("id").Parse() + ", please double-check the syntax."); } } return(container); }
private void NotificationMessageReceived(NotificationMessage msg) { //If this is not the intended target if (msg.Target != null && msg.Target != this) { return; } if (msg.Notification == "OpenFocusTree") { FocusGridModel container = msg.Sender as FocusGridModel; if (TabsModelList.Contains(container)) { return; } CheckForChanges(container); TabsModelList.Add(container); RaisePropertyChanged("TabsModelList"); } if (msg.Notification == "OpenLocalisation") { LocalisationModel container = msg.Sender as LocalisationModel; if (TabsModelList.Contains(container)) { return; } CheckForChanges(container); TabsModelList.Add(container); RaisePropertyChanged("TabsModelList"); } if (msg.Notification == "OpenEventList") { EventTabModel container = msg.Sender as EventTabModel; if (TabsModelList.Contains(container)) { return; } CheckForChanges(container); TabsModelList.Add(container); RaisePropertyChanged("TabsModelList"); } if (msg.Notification == "OpenScriptList") { ScriptModel container = msg.Sender as ScriptModel; if (TabsModelList.Contains(container)) { return; } CheckForChanges(container); TabsModelList.Add(container); RaisePropertyChanged("TabsModelList"); } if (msg.Notification == "SaveProject") { saveProject(); } if (msg.Notification == "RefreshProjectViewer") { TabsModelList.Clear(); RaisePropertyChanged("TabsModelList"); } if (msg.Notification == "SendDeleteItemSignal") { ObservableObject Model = null; if (msg.Sender is FocusGridModel) { Model = TabsModelList.FirstOrDefault((m) => m is FocusGridModel && ((FocusGridModel)m).UniqueID == ((FocusGridModel)msg.Sender).UniqueID); } else if (msg.Sender is LocalisationModel) { Model = TabsModelList.FirstOrDefault((m) => m is LocalisationModel && ((LocalisationModel)m).UniqueID == ((LocalisationModel)msg.Sender).UniqueID); } else if (msg.Sender is EventTabModel) { Model = TabsModelList.FirstOrDefault((m) => m is EventTabModel && ((EventTabModel)m).UniqueID == ((EventTabModel)msg.Sender).UniqueID); } else if (msg.Sender is ScriptModel) { Model = TabsModelList.FirstOrDefault((m) => m is ScriptModel && ((ScriptModel)m).UniqueID == ((ScriptModel)msg.Sender).UniqueID); } TabsModelList.Remove(Model); RaisePropertyChanged("TabsModelList"); } if (msg.Target == this) { //Resend to the tutorial View model if this was the target Messenger.Default.Send(new NotificationMessage(msg.Sender, new ViewModelLocator().Tutorial, msg.Notification)); } }