Exemplo n.º 1
0
        private static void InjectSubBehaviours(Level level, LevelBehaviour levelBehaviour)
        {
            var subBehaviourString = level.properties.GetString(Symbols.SubBehaviours);

            if (subBehaviourString == null)
            {
                levelBehaviour.subBehaviours = NoSubBehaviours;
                return;
            }

            var subBehaviours = subBehaviourString.Split(CommaSeparator, StringSplitOptions.RemoveEmptyEntries);

            if (subBehaviours.Length == 0)
            {
                levelBehaviour.subBehaviours = NoSubBehaviours;
                return;
            }

            var subList = new List <ILevelSubBehaviour>();

            foreach (var subBehaviour in subBehaviours)
            {
                CreateLevelSubBehaviourDelegate createSubMethod;
                if (levelSubCache.TryGetValue(subBehaviour, out createSubMethod))
                {
                    ILevelSubBehaviour levelSubBehaviour = createSubMethod();
                    subList.Add(levelSubBehaviour);
                }
            }

            levelBehaviour.subBehaviours = new ReadOnlyList <ILevelSubBehaviour>(subList);
        }
Exemplo n.º 2
0
        public virtual void LevelWillChange(UpdateContext updateContext, LevelBehaviour nextLevelBehaviour, Level nextLevel)
        {
            /* Handler for when the current level is about to be changed out */

            foreach (var subBehaviour in subBehaviours)
            {
                subBehaviour.LevelWillChange(updateContext, nextLevelBehaviour, nextLevel);
            }
        }
Exemplo n.º 3
0
        private static void InjectSubBehaviours(Level level, LevelBehaviour levelBehaviour, UpdateContext context)
        {
            var hasGlobalSubBehaviours = globalSubCache != null && globalSubCache.Count > 0;

            var subBehaviourString = level.properties.GetString(Symbols.SubBehaviours);

            if (!hasGlobalSubBehaviours && subBehaviourString == null)
            {
                levelBehaviour.subBehaviours = NoSubBehaviours;
                return;
            }

            string[] subBehaviours = null;
            if (subBehaviourString != null)
            {
                subBehaviours = subBehaviourString.Split(CommaSeparator, StringSplitOptions.RemoveEmptyEntries);
                if (!hasGlobalSubBehaviours && subBehaviours.Length == 0)
                {
                    levelBehaviour.subBehaviours = NoSubBehaviours;
                    return;
                }
            }

            var subList = new List <ILevelSubBehaviour>();

            if (hasGlobalSubBehaviours)
            {
                foreach (var globalSubBehaviour in globalSubCache)
                {
                    subList.Add(globalSubBehaviour.Value(level, context));
                }
            }

            if (subBehaviours != null)
            {
                foreach (var subBehaviour in subBehaviours)
                {
                    CreateLevelSubBehaviourDelegate createSubMethod;
                    if (levelSubCache.TryGetValue(subBehaviour, out createSubMethod))
                    {
                        subList.Add(createSubMethod(level, context));
                    }
                }
            }

            levelBehaviour.subBehaviours = new ReadOnlyList <ILevelSubBehaviour>(subList);
        }
Exemplo n.º 4
0
        public static LevelBehaviour CreateLevelBehaviour(string behaviour, Level level, UpdateContext context)
        {
            if (behaviour == null)
            {
                return(new LevelBehaviour());
            }

            CreateLevelBehaviourDelegate createMethod;

            if (levelCache.TryGetValue(behaviour, out createMethod))
            {
                LevelBehaviour levelBehaviour = createMethod(level, context);

                InjectSubBehaviours(level, levelBehaviour);

                return(levelBehaviour);
            }

            Debug.WriteLine("Missing LevelBehaviour called \"" + behaviour + "\"");
            return(new LevelBehaviour());
        }
Exemplo n.º 5
0
 public virtual void LevelWillChange(UpdateContext updateContext, LevelBehaviour nextLevelBehaviour, Level nextLevel)
 {
 }
Exemplo n.º 6
0
 public virtual void LevelWillChange(UpdateContext updateContext, LevelBehaviour nextLevelBehaviour)
 {
     /* Handler for when the current level is about to be changed out */
 }