Esempio n. 1
0
 public DMASTDefinitionParameter(DMASTPath path, DMASTExpression value, DMValueType type, DMASTExpression possibleValues)
 {
     Path           = path;
     Value          = value;
     Type           = type;
     PossibleValues = possibleValues;
 }
Esempio n. 2
0
        private void SetVariableValue(DMVariable variable, DMASTExpression value, DMValueType valType = DMValueType.Anything)
        {
            DMVisitorExpression._scopeMode = variable.IsGlobal ? "static" : "normal";
            DMExpression expression = DMExpression.Create(_currentObject, variable.IsGlobal ? DMObjectTree.GlobalInitProc : null, value, variable.Type);

            DMVisitorExpression._scopeMode = "normal";
            expression.ValType             = valType;

            if (expression.TryAsConstant(out var constant))
            {
                variable.Value = constant;
                return;
            }

            if (variable.IsConst)
            {
                throw new CompileErrorException(value.Location, "Value of const var must be a constant");
            }

            //Whether this should be initialized at runtime
            bool isValid = expression switch {
                //TODO: A better way of handling procs evaluated at compile time
                Expressions.ProcCall procCall => procCall.GetTargetProc(_currentObject).Proc?.Name switch {
                    "rgb" => true,
                    "generator" => true,
                    "matrix" => true,
                    "icon" => true,
                    "file" => true,
                    "sound" => true,
                    _ => variable.IsGlobal
                },
Esempio n. 3
0
 public override void ReadFromBuffer(NetIncomingMessage buffer)
 {
     PromptId     = buffer.ReadVariableInt32();
     Types        = (DMValueType)buffer.ReadUInt16();
     Title        = buffer.ReadString();
     Message      = buffer.ReadString();
     DefaultValue = buffer.ReadString();
 }
Esempio n. 4
0
        protected void FinishPrompt(DMValueType responseType, object value)
        {
            if (_responseSent)
            {
                return;
            }
            _responseSent = true;

            Program.OpenDream.Connection.SendPacket(new PacketPromptResponse(PromptId, responseType, value));
            Close();
        }
Esempio n. 5
0
        private void SetVariableValue(DMVariable variable, DMASTExpression value, DMValueType valType = DMValueType.Anything)
        {
            DMVisitorExpression._scopeMode = variable.IsGlobal ? "static" : "normal";
            DMExpression expression = DMExpression.Create(_currentObject, variable.IsGlobal ? DMObjectTree.GlobalInitProc : null, value, variable.Type);

            DMVisitorExpression._scopeMode = "normal";
            expression.ValType             = valType;

            if (expression.TryAsConstant(out var constant))
            {
                variable.Value = constant;
                return;
            }

            if (variable.IsConst)
            {
                throw new CompileErrorException(value.Location, "Value of const var must be a constant");
            }

            switch (expression)
            {
            case Expressions.List:
            case Expressions.NewList:
            case Expressions.NewPath:

            //TODO: A better way of handling procs evaluated at compile time
            case Expressions.ProcCall procCall when procCall.GetTargetProc(_currentObject).Proc?.Name == "rgb":
                variable.Value = new Expressions.Null(Location.Unknown);

                EmitInitializationAssign(variable, expression);
                break;

            case Expressions.ProcCall procCall when procCall.GetTargetProc(_currentObject).Proc?.Name == "generator":
                variable.Value = new Expressions.Null(Location.Unknown);

                EmitInitializationAssign(variable, expression);
                break;

            case Expressions.StringFormat:
            case Expressions.ProcCall:
                if (!variable.IsGlobal)
                {
                    throw new CompileErrorException(value.Location, $"Invalid initial value for \"{variable.Name}\"");
                }

                variable.Value = new Expressions.Null(Location.Unknown);
                EmitInitializationAssign(variable, expression);
                break;

            default:
                throw new CompileErrorException(value.Location, $"Invalid initial value for \"{variable.Name}\"");
            }
        }
Esempio n. 6
0
        public override void ReadFromBuffer(NetIncomingMessage buffer)
        {
            PromptId = buffer.ReadVariableInt32();
            Type     = (DMValueType)buffer.ReadUInt16();

            Value = Type switch
            {
                DMValueType.Null => null,
                DMValueType.Text or DMValueType.Message => buffer.ReadString(),
                DMValueType.Num => buffer.ReadSingle(),
                _ => throw new ArgumentOutOfRangeException()
            };
        }
Esempio n. 7
0
        protected void FinishPrompt(DMValueType responseType, object value)
        {
            if (_responseSent)
            {
                return;
            }
            _responseSent = true;

            var msg = _netManager.CreateNetMessage <MsgPromptResponse>();

            msg.PromptId = _promptId;
            msg.Type     = responseType;
            msg.Value    = value;
            _netManager.ClientSendMessage(msg);
        }
Esempio n. 8
0
        protected void FinishPrompt(DMValueType responseType, object value)
        {
            if (_responseSent)
            {
                return;
            }
            _responseSent = true;

            var msg = new MsgPromptResponse()
            {
                PromptId = _promptId,
                Type     = responseType,
                Value    = value
            };

            _netManager.ClientSendMessage(msg);
        }
Esempio n. 9
0
        public void ReadFromStream(PacketStream stream)
        {
            PromptId = stream.ReadUInt16();

            Type = (DMValueType)stream.ReadUInt16();
            switch (Type)
            {
            case DMValueType.Null: Value = null; break;

            case DMValueType.Text: Value = stream.ReadString(); break;

            case DMValueType.Num: Value = stream.ReadInt32(); break;

            case DMValueType.Message: Value = stream.ReadString(); break;

            default: throw new Exception("Invalid prompt response type '" + Type + "'");
            }
        }
Esempio n. 10
0
 public DMASTInput(DMASTCallParameter[] parameters, DMValueType types, DMASTExpression list)
 {
     Parameters = parameters;
     Types      = types;
     List       = list;
 }
Esempio n. 11
0
 public void ReadFromStream(PacketStream stream)
 {
     PromptId = stream.ReadUInt16();
     Types    = (DMValueType)stream.ReadUInt16();
     Message  = stream.ReadString();
 }
Esempio n. 12
0
 public PacketPrompt(int promptId, DMValueType types, string message)
 {
     PromptId = promptId;
     Types    = types;
     Message  = message;
 }
Esempio n. 13
0
 public PacketPromptResponse(int promptId, DMValueType type, object value)
 {
     PromptId = promptId;
     Type     = type;
     Value    = value;
 }