Esempio n. 1
0
        public void SetLogLevel(LogLevel lv)
        {
            List <LogLevel> lvs = new List <LogLevel>();

            foreach (var ll in Enum.GetValues(typeof(LogLevel)))
            {
                if ((int)ll >= (int)lv)
                {
                    lvs.Add((LogLevel)ll);
                }
            }
            LevelRule.SetValid(lvs);
        }
Esempio n. 2
0
 void Awake()
 {
     gemList = new List <GemController>();
     myRule  = gameObject.GetComponent <LevelRule>();
     //Debug.Log("my rule : " + myRule);
 }
Esempio n. 3
0
        /// <summary>
        /// Generates a native file byte array of the object.
        /// </summary>
        /// <returns>The byte array to save.</returns>
        public override byte[] ToByteArray()
        {
            if (_xmlLevelRules == null)
            {
                throw new Exceptions.NotInitializedException();
            }
            if (String.IsNullOrEmpty(_xmlLevelRules.FileHeader.RuleName))
            {
                throw new Exceptions.InvalidXmlElement("LevelRulesName", "Cannot be empty.");
            }
            if (_xmlLevelRules.LevelRules == null)
            {
                throw new Exceptions.InvalidXmlElement("LevelRules", "Cannot be empty.");
            }
            int ruleCount = _xmlLevelRules.LevelRules.Length;

            if (ruleCount == 0)
            {
                throw new Exceptions.InvalidXmlElement("LevelRules", "Cannot be empty.");
            }

            int offset = 0;

            byte[] fileBytes = new byte[1024];


            // write header
            FileTools.WriteToBuffer(ref fileBytes, ref offset, FileMagicWord);
            FileTools.WriteToBuffer(ref fileBytes, ref offset, RequiredVersion);


            // level rules header
            offset += Marshal.SizeOf(typeof(LevelRulesHeader));


            // level rules
            LevelRulesStaticFooter[] levelRulesStaticFooters = null;
            LevelRulesRandomFooter[] levelRulesRandomFooters = null;
            for (int i = 0; i < ruleCount; i++)
            {
                LevelRule levelRule = _xmlLevelRules.LevelRules[i];

                // static rules
                if (_xmlLevelRules.LevelRules[i].StaticRooms != null)
                {
                    if (levelRule.StaticRooms.Length == 0)
                    {
                        throw new Exceptions.InvalidXmlElement("StaticRooms", "Cannot be empty");
                    }

                    if (levelRulesStaticFooters == null)
                    {
                        levelRulesStaticFooters = new LevelRulesStaticFooter[ruleCount];
                    }
                    levelRulesStaticFooters[i] = new LevelRulesStaticFooter
                    {
                        RoomCount  = levelRule.StaticRooms.Length,
                        RuleOffset = offset
                    };

                    _WriteRooms(levelRule.StaticRooms, ref fileBytes, ref offset);
                }
                else if (_xmlLevelRules.LevelRules[i].Rules != null) // random rules
                {
                    if (levelRule.Rules.Length == 0)
                    {
                        throw new Exceptions.InvalidXmlElement("Rules", "Cannot be empty");
                    }

                    if (levelRulesRandomFooters == null)
                    {
                        levelRulesRandomFooters = new LevelRulesRandomFooter[ruleCount];
                    }
                    levelRulesRandomFooters[i] = new LevelRulesRandomFooter();

                    if (levelRule.ConnectorRooms != null && levelRule.ConnectorRooms.Length > 0)
                    {
                        levelRulesRandomFooters[i].ConnectorRoomCount  = levelRule.ConnectorRooms.Length;
                        levelRulesRandomFooters[i].ConnectorRuleOffset = offset;
                        _WriteRooms(levelRule.ConnectorRooms, ref fileBytes, ref offset);
                    }

                    levelRulesRandomFooters[i].RuleCount   = levelRule.Rules.Length;
                    levelRulesRandomFooters[i].RoomCounts  = new Int32[32];
                    levelRulesRandomFooters[i].RuleOffsets = new Int64[32];
                    for (int j = 0; j < levelRule.Rules.Length; j++)
                    {
                        levelRulesRandomFooters[i].RoomCounts[j]  = levelRule.Rules[j].Length;
                        levelRulesRandomFooters[i].RuleOffsets[j] = offset;
                        _WriteRooms(levelRule.Rules[j], ref fileBytes, ref offset);
                    }
                }
                else
                {
                    throw new Exceptions.InvalidXmlDocument("No StaticRooms or Rules elements found!");
                }
            }


            // footer details and initial offsets
            _xmlLevelRules.FileHeader._internalInt321 = -1;
            if (levelRulesStaticFooters != null)
            {
                _xmlLevelRules.FileHeader.StaticRulesCount        = ruleCount;
                _xmlLevelRules.FileHeader.StaticRulesFooterOffset = offset;
                FileTools.WriteToBuffer(ref fileBytes, ref offset, levelRulesStaticFooters.ToByteArray());
            }
            if (levelRulesRandomFooters != null)
            {
                _xmlLevelRules.FileHeader.RandomRulesCount        = ruleCount;
                _xmlLevelRules.FileHeader.RandomRulesFooterOffset = offset;
                FileTools.WriteToBuffer(ref fileBytes, ref offset, levelRulesRandomFooters.ToByteArray());
            }


            // write file header
            FileTools.WriteToBuffer(ref fileBytes, 0x08, _xmlLevelRules.FileHeader);


            // and we're done
            Array.Resize(ref fileBytes, offset);
            return(fileBytes);
        }
Esempio n. 4
0
 public void Start()
 {
     levelRule   = GameObject.FindGameObjectWithTag("LevelRule").GetComponent <LevelRule>();
     sceneObject = GameObject.FindGameObjectWithTag("SceneObject");
 }