/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode or KmlAttrib or further derived from these. /// When an KmlAttrib "Name" is found, its value will be used for the "Name" property /// of this node. /// </summary> /// <param name="item">The KmlItem to add</param> public virtual void Add(KmlItem item) { AllItems.Add(item); if (item is KmlNode) { Children.Add((KmlNode)item); } else if (item is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)item; if (attrib.Name.ToLower() == "name") { Name = attrib.Value; // Get notified when Name changes attrib.AttribValueChanged += Name_Changed; attrib.CanBeDeleted = false; } Attribs.Add(attrib); } else { Unknown.Add(item); Syntax.Warning(this, "Unknown line in persistence file: " + item.ToString()); } }
public static WorldState CreateWorldState(string attributesDefinitionPath = Constants.AttributesDefinitionLoc) { AttributesDefinition attribsDef = XmlUtils.LoadAttributes(attributesDefinitionPath); Dictionary <AttribsCategory, Attribs> stateVariables = new Dictionary <AttribsCategory, Attribs>(); Dictionary <string, Attrib> attribsByName = new Dictionary <string, Attrib>(); foreach (var categoryDao in attribsDef.Categories) { var category = new AttribsCategory(categoryDao.Name, categoryDao.Description); var attribsSet = new Attribs(); stateVariables.Add(category, attribsSet); foreach (var attribDao in categoryDao.Attributes) { var color = GetSliderColor(attribDao); Attrib attrib = new Attrib(attribDao.Description) { IsDisplayed = attribDao.IsDisplayed, Category = category, Color = color }; attribsByName.Add(attribDao.Name, attrib); attribsSet[attrib] = attribDao.InitialValue; } } WorldState state = new WorldState { AllStates = stateVariables }; Attribs.SetAttribsCollection(attribsByName); PutCategoriesIntoVariables(stateVariables, state); return(state); }
/// <summary> /// Deletes a KmlItem from this nodes lists. /// Result will be false if item was not in the lists or couldn't be deleted /// because of restrictions. /// </summary> /// <param name="item">The KmlItem to delete</param> /// <returns>True if item was deleted, false otherwise</returns> public virtual bool Delete(KmlItem item) { if (!item.CanBeDeleted) { return(false); } // Call itme's Delete to call it's BeforeDelete() // But there would usually be called this method, // to avoid loop we set parent to null. // We also ignore result, will be false in that case RemapParent(item, null); item.Delete(); if (!AllItems.Remove(item)) { // It wasn't in the list, nothing to do return(false); } if (item is KmlAttrib) { bool result = Attribs.Remove((KmlAttrib)item); InvokeAttribChanged(); return(result); } else if (item is KmlNode) { bool result = Children.Remove((KmlNode)item); InvokeChildrenChanged(); return(result); } else { return(Unknown.Remove(item)); } }
public void TestConditionalAttribsCompare() { var worldState = GameInit.CreateWorldState("Attributes/credibility_and_money"); var condScenario = new ConditionalEventsScenario("Scenarios/test_conditional_attribcmp", worldState); var cred = Attribs.GetAttribByName("Credibility"); var money = Attribs.GetAttribByName("Money"); worldState.JournalistState[cred] = 500; worldState.SetValue(money, 500); var scheduler = new PressEventScheduler(worldState, new DateTime(1605, 1, 1), new DateTime(2020, 2, 2), condScenario); Assert.IsNull(scheduler.PopNextEvent()); worldState.SetValue(money, 499); Assert.AreEqual("More credibility", scheduler.PopNextEvent().Name); Assert.IsNull(scheduler.PopNextEvent()); worldState.SetValue(money, 501); Assert.AreEqual("More money", scheduler.PopNextEvent().Name); Assert.IsNull(scheduler.PopNextEvent()); worldState.SetValue(cred, 100); worldState.SetValue(money, 101); Assert.IsNull(scheduler.PopNextEvent()); worldState.SetValue(money, 100); Assert.AreEqual("Little of both", scheduler.PopNextEvent().Name); Assert.IsNull(scheduler.PopNextEvent()); worldState.Date = new DateTime(2016, 12, 12); Assert.AreEqual("Late", scheduler.PopNextEvent().Name); Assert.IsNull(scheduler.PopNextEvent()); Assert.IsTrue(condScenario.IsTerminated); }
public void TestConditional1() { var worldState = GameInit.CreateWorldState("Attributes/credibility_and_money"); var storyEventsScenario = new StoryEventsScenario("Attributes/test_story_effects"); var condScenario = new ConditionalEventsScenario("Scenarios/test_conditional", worldState); var cred = Attribs.GetAttribByName("Credibility"); var money = Attribs.GetAttribByName("Money"); worldState.JournalistState[cred] = 0; var scheduler = new PressEventScheduler(worldState, new DateTime(2016, 1, 1), new DateTime(2017, 2, 2), storyEventsScenario, condScenario); Assert.AreEqual(500, worldState.JournalistState[money]); var cond = scheduler.PopNextEvent(); Assert.IsNotNull(cond as CutsceneEvent); Assert.AreEqual("Unconditional conditional!", (cond as CutsceneEvent).Description); var evt = NextAsMultipleChoice(scheduler); evt.Apply(evt.Choices[1], worldState); Assert.AreEqual(250, worldState.JournalistState[cred]); evt = NextAsMultipleChoice(scheduler); Assert.AreEqual("Credibility is 250.", evt.Description); evt.Apply(evt.Choices[0], worldState); Assert.AreEqual(0, worldState.JournalistState[money]); evt = NextAsMultipleChoice(scheduler); evt.Apply(evt.Choices[0], worldState); Assert.AreEqual(275, worldState.JournalistState[cred]); Assert.IsNull(scheduler.PopNextEvent()); }
protected override void OnConfigureAttributes(Attribs <ConfigAttributes> attribs) { attribs.Add(ConfigAttributes.EGL_RED_SIZE, 5); attribs.Add(ConfigAttributes.EGL_GREEN_SIZE, 6); attribs.Add(ConfigAttributes.EGL_BLUE_SIZE, 5); attribs.Add(ConfigAttributes.EGL_DEPTH_SIZE, 16); attribs.AddEnd(); }
/// <summary> /// Clear all child nodes and attributes from this node. /// Deriving classes should override this and clear their stuff, /// but call base.Clear() within. /// </summary> public virtual void Clear() { Attribs.Clear(); Children.Clear(); Unknown.Clear(); AllItems.Clear(); Name = ""; }
private void InitializeGraphics() { try { // platform graphics setup this.RenderingWindow = new RenderingWindow(); this.RenderingWindow.Show(); this.DisplayManager = new DisplayManager(); this.PlatformManager = new PlatformGraphicsManager(this.DisplayManager.GetDisplay(this.RenderingWindow)); this.PlatformManager.BindApi(Api.EGL_OPENGL_ES_API); var attribs = new Attribs <ConfigAttributes>(); this.OnConfigureAttributes(attribs); var config = this.PlatformManager.ChooseConfigs(attribs, 1).FirstOrDefault(); if (config == null) { throw new InvalidOperationException("Could not find matching configuration"); } this.RenderingContext = this.PlatformManager.CreateContext(config, ContextVersion.OPENGL_ES_2); this.RenderingSurface = this.PlatformManager.CreateWindowSurface(config, this.RenderingWindow); this.RenderingContext.MakeCurrent(this.RenderingSurface, this.RenderingSurface); // graphics device setup this.GraphicsDevice = new GraphicsDevice { ClearColor = new Vector4(1, 1, 1, 1f), Viewport = new Rectangle( 0, 0, this.RenderingWindow.Width, this.RenderingWindow.Height) }; var error = NativeGl.glGetError(); if (error != NativeGl.GL_NO_ERROR) { throw new InvalidOperationException("Error while initializing graphics."); } } catch (PlatformGraphicsException x) { MessageBox.Show(x.ToString()); this.ExitGame = true; } }
private KmlAttrib GetNextSibling(KmlAttrib attrib) { int index = Attribs.IndexOf(attrib); if (index >= 0 && index < Attribs.Count - 1) { return(Attribs[index + 1]); } else { return(null); } }
/// <summary> /// Retrieve the attribute locations using the attribute names and add them to Attribs. /// </summary> /// <param name="gl"></param> /// <param name="attributeNames"></param> private void AddAttributeIds(OpenGL gl, IEnumerable <string> attributeNames) { if (Attribs == null) { Attribs = new Dictionary <string, uint>(); } foreach (var name in attributeNames) { var location = gl.GetAttribLocation(ShaderProgramId, name); Attribs.Add(name, (uint)location); } }
public static Precondition FromDao(PreconditionDao dao) { if (dao.AttributeName == "date") { return(CreateDatePrecond(dao.Operation, dao.Value)); } var attribute = Attribs.GetAttribByName(dao.AttributeName); var valStr = dao.Value; int val; bool isNum = Int32.TryParse(valStr, out val); Attrib comparedAttrib = null; if (!isNum) { comparedAttrib = Attribs.GetAttribByName(valStr); } switch (dao.Operation) { case PreconditionOp.LessThan: if (isNum) { return(new LessThanPrecondition(attribute, val)); } return(new LessThanAttribPrecondition(attribute, comparedAttrib)); case PreconditionOp.GreaterThan: if (isNum) { return(new GreaterThanPrecondition(attribute, val)); } return(new GreaterThanAttribPrecondition(attribute, comparedAttrib)); case PreconditionOp.Equal: if (isNum) { return(new EqualPrecondition(attribute, val)); } return(new EqualAttribPrecondition(attribute, comparedAttrib)); case PreconditionOp.LessOrEqual: if (isNum) { return(new LessOrEqualPrecondition(attribute, val)); } return(new LessOrEqualAttribPrecondition(attribute, comparedAttrib)); default: throw new ArgumentOutOfRangeException(); } }
public void TestAttributesAndTermination() { var worldState = GameInit.CreateWorldState("Attributes/credibility_only"); var storyEventsScenario = new StoryEventsScenario("Attributes/test_story_effects"); var cred = Attribs.GetAttribByName("Credibility"); var scheduler = new PressEventScheduler(worldState, new DateTime(2016, 1, 1), new DateTime(2017, 2, 2), storyEventsScenario); var evt = NextAsMultipleChoice(scheduler); Assert.AreEqual(500, worldState.JournalistState[cred]); evt.Apply(evt.Choices[0], worldState); Assert.AreEqual(125, worldState.JournalistState[cred]); evt = NextAsMultipleChoice(scheduler); evt.Apply(evt.Choices[0], worldState); Assert.AreEqual(150, worldState.JournalistState[cred]); Assert.IsNull(scheduler.PopNextEvent()); }
public Html(string tag = "html", string? @class = null, string?id = null) { Attr = new Attribs(); Children = new List <Html>(); NewLine = Environment.NewLine; Parent = null; Tag = tag; if (@class != null) { Attr.Add("class", @class); } if (id != null) { Attr.Add("id", id); } }
public void TestNotMatchingDates() { var worldState = GameInit.CreateWorldState("Attributes/credibility_and_money"); var storyEventsScenario = new StoryEventsScenario("Attributes/test_story_effects"); var condScenario = new ConditionalEventsScenario("Scenarios/test_conditional", worldState); var cred = Attribs.GetAttribByName("Credibility"); var money = Attribs.GetAttribByName("Money"); worldState.JournalistState[cred] = 500; var scheduler = new PressEventScheduler(worldState, new DateTime(1605, 1, 1), new DateTime(1606, 2, 2), storyEventsScenario, condScenario); Assert.AreEqual(500, worldState.JournalistState[money]); var cond = scheduler.PopNextEvent(); Assert.IsNotNull(cond as CutsceneEvent); Assert.AreEqual("Unconditional conditional!", (cond as CutsceneEvent).Description); Assert.IsNull(scheduler.PopNextEvent()); }
private static WorldState CreateWorldState(int initialCredibility) { WorldState state = new WorldState(); var journalistState = new Attribs(); state.JournalistState = journalistState; var category = new AttribsCategory("journalist", "journalist states"); Attribs.Credibility.Category = category; state.AllStates = new Dictionary <AttribsCategory, Attribs>() { { category, journalistState } }; state.JournalistState[Attribs.Credibility] = initialCredibility; Attribs.SetAttribsCollection(new Dictionary <string, Attrib>() { { "Credibility", Attribs.Credibility } }); return(state); }
// Update is called once per frame void Update() { if (buttonApply) { buttonApply = false; for (int i = 0; i < skipEventsCount; i++) { _scheduler.PopNextEvent(); } var info = Attribs.GetAttribByName("Info"); var panic = Attribs.GetAttribByName("Panic"); var fun = Attribs.GetAttribByName("Fun"); var tom = Attribs.GetAttribByName("Tom"); var alice = Attribs.GetAttribByName("Alice"); var s = WorldStateProvider.State; s.AddToValue(alice, addToAttributeAlice); s.AddToValue(panic, addToAttributePanic); s.AddToValue(tom, addToAttributeTom); s.AddToValue(fun, addToAttributeFun); s.AddToValue(info, addToAttributeInfo); } if (_currentEvent == null) { return; } if (_currentEvent.IsFinished) { _currentEvent = _scheduler.PopNextEvent(); if (_currentEvent != null) { _currentEvent.ProcessEvent(Processor); } else { GetComponent <ScenePicker>().LoadScene(); } } }
public void TestBasic() { var initialCredibility = 450; var state = CreateWorldState(initialCredibility); Attribs.SetAttribsCollection(new Dictionary <string, Attrib>() { { "Credibility", Attribs.Credibility } }); StoryEventsScenario scenario = new StoryEventsScenario("Scenarios/test_story"); IPressEventScheduler scheduler = new PressEventScheduler(state, new DateTime(1989, 11, 17), new DateTime(1990, 1, 1), scenario); var evt = scheduler.PopNextEvent(); Assert.AreEqual(new DateTime(1989, 11, 17), evt.Date); Assert.AreEqual(0, evt.Preconditions.Count); Assert.AreEqual(typeof(CutsceneEvent), evt.GetType()); Assert.AreEqual(evt.Date, new DateTime(1989, 11, 17)); evt = scheduler.PopNextEvent(); Assert.AreEqual("EventLowCredibility", ((CutsceneEvent)evt).Description); evt = scheduler.PopNextEvent(); Assert.AreEqual(null, evt); }
protected abstract void OnConfigureAttributes(Attribs <ConfigAttributes> attribs);
public Effect Process(MoveTowardsEffectDao effect) { return(new MoveTowardsEffect(Attribs.GetAttribByName(effect.Attribute), effect.Value, effect.Amount)); }
/// <summary> /// Adds (inserts before) a child KmlItem to this nodes lists of children. /// If item to insert before is null or not contained, it will be added at the end. /// This is the basic add method, derived classes can override but should /// always call base.Add(beforeItem, newItem) within. /// Public Add, AddRange, InsertBefore and InsertAfter all use this protected /// method to access the lists. /// <see cref="KML.KmlNode.Add(KML.KmlItem)"/> /// </summary> /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param> /// <param name="newItem">The KmlItem to add</param> protected virtual void Add(KmlItem beforeItem, KmlItem newItem) { // ensure that item.Parent is this node if (newItem.Parent != this) { RemapParent(newItem, this); } // Not add always to end of AllItems, add well ordered: attribs first, then nodes. // Like Add(attrib), Add(Node), Add(attrib) should result in attrib, attrib, node if (newItem is KmlAttrib && !(beforeItem is KmlAttrib) && Children.Count > 0) { Syntax.Warning(newItem, "KML attribute should not come after nodes, will be fixed when saved"); beforeItem = Children[0]; } if (beforeItem != null && AllItems.Contains(beforeItem)) { AllItems.Insert(AllItems.IndexOf(beforeItem), newItem); } else { AllItems.Add(newItem); } if (newItem is KmlNode) { if (beforeItem is KmlNode && Children.Contains((KmlNode)beforeItem)) { Children.Insert(Children.IndexOf((KmlNode)beforeItem), (KmlNode)newItem); } else { Children.Add((KmlNode)newItem); } InvokeChildrenChanged(); } else if (newItem is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)newItem; if (attrib.Name.ToLower() == "name") { if (Name.Length == 0) { Name = attrib.Value; // Get notified when Name changes attrib.AttribValueChanged += Name_Changed; attrib.CanBeDeleted = false; // And notify that the name changed InvokeToStringChanged(); } } if (beforeItem is KmlAttrib && Attribs.Contains((KmlAttrib)beforeItem)) { Attribs.Insert(Attribs.IndexOf((KmlAttrib)beforeItem), attrib); } else { Attribs.Add(attrib); } InvokeAttribChanged(); } else { if (beforeItem != null && Unknown.Contains(newItem)) { Unknown.Insert(Unknown.IndexOf(beforeItem), newItem); } else { Unknown.Add(newItem); } Syntax.Warning(this, "Unknown line in persistence file: " + newItem.ToString()); } }
public Effect Process(ModifyEffectDao effect) { return(new ModifyEffect(Attribs.GetAttribByName(effect.Attribute), effect.Value)); }