예제 #1
0
        public static TriggerFunctionParameter Parse(Stream stream, TriggerData triggerData, MapTriggersFormatVersion formatVersion, bool leaveOpen)
        {
            var parameter = new TriggerFunctionParameter();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
            {
                parameter._type  = reader.ReadInt32 <TriggerFunctionParameterType>();
                parameter._value = reader.ReadChars();

                var haveFunction = reader.ReadBool();
                if (haveFunction)
                {
                    if (parameter._type != TriggerFunctionParameterType.Function)
                    {
                        throw new InvalidDataException($"Parameter must be of type '{TriggerFunctionParameterType.Function}' to have a function.");
                    }

                    parameter._function = TriggerFunction.Parse(stream, triggerData, formatVersion, false, true);
                }

                var haveArrayIndexer = reader.ReadBool();
                if (haveArrayIndexer)
                {
                    if (parameter._type != TriggerFunctionParameterType.Variable)
                    {
                        throw new InvalidDataException($"Parameter must be of type '{TriggerFunctionParameterType.Variable}' to have an array indexer.");
                    }

                    parameter._arrayIndexer = Parse(stream, triggerData, formatVersion, true);
                }
            }

            return(parameter);
        }
예제 #2
0
        public static TriggerFunction Parse(Stream stream, TriggerData triggerData, MapTriggersFormatVersion formatVersion, bool isChildFunction, bool leaveOpen)
        {
            var function = new TriggerFunction();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
            {
                function._type      = reader.ReadInt32 <TriggerFunctionType>();
                function._branch    = isChildFunction ? reader.ReadInt32() : -1;
                function._name      = reader.ReadChars();
                function._isEnabled = reader.ReadBool();

                var parameterCount = triggerData.GetParameterCount(function._type, function._name);
                for (var i = 0; i < parameterCount; i++)
                {
                    function._parameters.Add(TriggerFunctionParameter.Parse(stream, triggerData, formatVersion, true));
                }

                if (formatVersion >= MapTriggersFormatVersion.Tft)
                {
                    var nestedfunctionCount = reader.ReadInt32();
                    if (nestedfunctionCount > 0)
                    {
                        for (var i = 0; i < nestedfunctionCount; i++)
                        {
                            function._nestedFunctions.Add(Parse(stream, triggerData, formatVersion, true, true));
                        }
                    }
                }
            }

            return(function);
        }