Inheritance: IComponentInfo
        public IComponentInfo Load(XElement node, Project project)
        {
            var comp = new StateComponentInfo();
            foreach (var state in node.Elements("State"))
            {
                var stateInfo = ReadState(state);
                comp.States.Add(stateInfo);
            }

            foreach (var triggerInfo in node.Elements("Trigger"))
            {
                var statesNode = triggerInfo.Element("States");
                var states = statesNode != null ? statesNode.Value.Split(',').Select(s => s.Trim()).ToList() : null;

                var trigger = _triggerReader.Load(triggerInfo);

                if (trigger.Priority == null)
                    trigger.Priority = ((IXmlLineInfo)triggerInfo).LineNumber;

                comp.Triggers.Add(new MultiStateTriggerInfo() {
                    States = states,
                    Trigger = trigger
                });
            }

            return comp;
        }
 private void LoadStateComponent(GameEntity entity, StateComponentInfo info)
 {
     var comp = new StateComponent();
     entity.AddComponent(comp);
     comp.LoadInfo(info);
 }
Exemplo n.º 3
0
        internal void LoadInfo(StateComponentInfo componentInfo)
        {
            foreach (var stateInfo in componentInfo.States)
            {
                var state = new State() { Name = stateInfo.Name };
                foreach (var trigger in stateInfo.Triggers)
                {
                    state.AddTrigger(ParseTrigger(trigger));
                }

                state.SetInitial(EffectParser.LoadTriggerEffect(stateInfo.Initializer));
                state.SetLogic(EffectParser.LoadTriggerEffect(stateInfo.Logic));

                states[state.Name] = state;
            }

            foreach (var triggerInfo in componentInfo.Triggers)
            {
                var trigger = ParseTrigger(triggerInfo.Trigger);

                if (triggerInfo.States != null)
                {
                    foreach (var stateName in triggerInfo.States)
                    {
                        if (!states.ContainsKey(stateName))
                        {
                            State state = new State {Name = stateName};
                            states.Add(stateName, state);
                        }
                        states[stateName].AddTrigger(trigger);
                    }
                }
                else
                {
                    foreach (var state in states.Values)
                    {
                        state.AddTrigger(trigger);
                    }
                }
            }
        }