Ejemplo n.º 1
0
        public override void Translate(ActionSet actionSet)
        {
            WorkshopVariable variable;
            Element          target;
            Element          start;

            // Existing variable being used in for.
            if (VariableResolve != null)
            {
                VariableElements elements = VariableResolve.ParseElements(actionSet);
                variable = elements.IndexReference.WorkshopVariable;
                target   = elements.Target;
                start    = (Element)InitialResolveValue?.Parse(actionSet) ?? new V_Number(0);
            }
            // New variable being use in for.
            else
            {
                actionSet.IndexAssigner.Add(actionSet.VarCollection, DefinedVariable, actionSet.IsGlobal, null);
                variable = ((IndexReference)actionSet.IndexAssigner[DefinedVariable]).WorkshopVariable;
                target   = new V_EventPlayer();
                start    = (Element)DefinedVariable.InitialValue?.Parse(actionSet) ?? new V_Number(0);
            }

            Element stop = (Element)Stop.Parse(actionSet);
            Element step = (Element)Step.Parse(actionSet);

            // Global
            if (variable.IsGlobal)
            {
                actionSet.AddAction(Element.Part <A_ForGlobalVariable>(
                                        variable,
                                        start, stop, step
                                        ));
            }
            // Player
            else
            {
                actionSet.AddAction(Element.Part <A_ForPlayerVariable>(
                                        target,
                                        variable,
                                        start, stop, step
                                        ));
            }

            // Translate the block.
            Block.Translate(actionSet.Indent());

            // Resolve continues.
            ResolveContinues(actionSet);

            // Cap the for.
            actionSet.AddAction(new A_End());

            // Resolve breaks.
            ResolveBreaks(actionSet);
        }
        public void Translate(ActionSet actionSet)
        {
            VariableElements elements = _resolve.ParseElements(actionSet);

            // Increment
            if (!_decrement)
            {
                actionSet.AddAction(SetVariableAction.CommentAll(_comment, elements.IndexReference.ModifyVariable(Operation.Add, 1, elements.Target, elements.Index)));
            }
            // Decrement
            else
            {
                actionSet.AddAction(SetVariableAction.CommentAll(_comment, elements.IndexReference.ModifyVariable(Operation.Subtract, 1, elements.Target, elements.Index)));
            }
        }
        public void Translate(ActionSet actionSet)
        {
            VariableElements elements = _resolve.ParseElements(actionSet);

            // Increment
            if (!_decrement)
            {
                elements.IndexReference.Modify(actionSet, Operation.Add, (Element)1, elements.Target, elements.Index);
            }
            // Decrement
            else
            {
                elements.IndexReference.Modify(actionSet, Operation.Subtract, (Element)1, elements.Target, elements.Index);
            }
        }
Ejemplo n.º 4
0
        public void Translate(ActionSet actionSet)
        {
            VariableElements elements = VariableResolve.ParseElements(actionSet);

            Element value = null;

            if (Value != null)
            {
                value = (Element)Value.Parse(actionSet);
            }

            Elements.Operation?modifyOperation = null;
            switch (Operation)
            {
            case "=": break;

            case "^=": modifyOperation = Elements.Operation.RaiseToPower; break;

            case "*=": modifyOperation = Elements.Operation.Multiply;     break;

            case "/=": modifyOperation = Elements.Operation.Divide;       break;

            case "%=": modifyOperation = Elements.Operation.Modulo;       break;

            case "+=": modifyOperation = Elements.Operation.Add;          break;

            case "-=": modifyOperation = Elements.Operation.Subtract;     break;

            case "++": value = 1; modifyOperation = Elements.Operation.Add;      break;

            case "--": value = 1; modifyOperation = Elements.Operation.Subtract; break;

            default: throw new Exception($"Unknown operation {Operation}.");
            }

            if (modifyOperation == null)
            {
                actionSet.AddAction(elements.IndexReference.SetVariable(value, elements.Target, elements.Index));
            }
            else
            {
                actionSet.AddAction(elements.IndexReference.ModifyVariable((Elements.Operation)modifyOperation, value, elements.Target, elements.Index));
            }
        }
Ejemplo n.º 5
0
 public WorkshopParameter(IWorkshopTree value, object additionalData, VariableElements refVariableElements)
 {
     Value               = value;
     AdditionalData      = additionalData;
     RefVariableElements = refVariableElements;
 }
Ejemplo n.º 6
0
        public void Translate(ActionSet actionSet)
        {
            VariableElements elements = VariableResolve.ParseElements(actionSet);

            Element value = null;

            if (Value != null)
            {
                value = (Element)Value.Parse(actionSet);
            }

            Elements.Operation?modifyOperation = null;
            switch (Operation)
            {
            case "=": break;

            case "^=": modifyOperation = Elements.Operation.RaiseToPower; break;

            case "*=": modifyOperation = Elements.Operation.Multiply;     break;

            case "/=": modifyOperation = Elements.Operation.Divide;       break;

            case "%=": modifyOperation = Elements.Operation.Modulo;       break;

            case "+=": modifyOperation = Elements.Operation.Add;          break;

            case "-=": modifyOperation = Elements.Operation.Subtract;     break;

            case "++": value = 1; modifyOperation = Elements.Operation.Add;      break;

            case "--": value = 1; modifyOperation = Elements.Operation.Subtract; break;

            default: throw new Exception($"Unknown operation {Operation}.");
            }

            // The actions used to set the variable.
            Element[] actions;

            // Set Variable actions
            if (modifyOperation == null)
            {
                actions = elements.IndexReference.SetVariable(value, elements.Target, elements.Index);
            }
            // Modify Variable actions
            else
            {
                actions = elements.IndexReference.ModifyVariable((Elements.Operation)modifyOperation, value, elements.Target, elements.Index);
            }

            // Add the actions to the action set.
            actionSet.AddAction(actions);

            // Set action comments
            if (Comment != null)
            {
                // If there is just one action used to set or modify the variable, set that action's comment.
                if (actions.Length == 1)
                {
                    actions[0].Comment = Comment;
                }
                // If multiple actions are required, precede the comment with (#) where # is the order of the relevent action.
                else
                {
                    for (int i = 0; i < actions.Length; i++)
                    {
                        actions[i].Comment = "(" + i + ") " + Comment;
                    }
                }
            }
        }