コード例 #1
0
        public IndexReference Assign(string name, VariableType variableType, bool isGlobal, bool extended, int id)
        {
            bool variableIsGlobal = variableType == VariableType.Dynamic ? isGlobal : variableType == VariableType.Global;

            if (!extended)
            {
                if (id == -1)
                {
                    return(new IndexReference(ArrayBuilder, AssignWorkshopVariable(name, variableIsGlobal)));
                }
                else
                {
                    WorkshopVariable workshopVariable = new WorkshopVariable(variableIsGlobal, id, MetaElement.WorkshopNameFromCodeName(name, NamesTaken(variableIsGlobal)));
                    variableList(variableIsGlobal).Add(workshopVariable);
                    return(new IndexReference(ArrayBuilder, workshopVariable));
                }
            }
            else
            {
                int            index     = NextFreeExtended(variableIsGlobal);
                IndexReference reference = new IndexReference(ArrayBuilder, GetExtendedCollection(variableIsGlobal), Element.Num(index));
                ExtendedVariableList(variableIsGlobal).Add(new ExtendedVariable(name, reference, index));
                return(reference);
            }
        }
コード例 #2
0
 private ElementOrigin(bool isGlobal, Element player, WorkshopVariable variable, Element[] index)
 {
     IsGlobal = isGlobal;
     Player   = player;
     Variable = variable;
     Index    = index;
 }
コード例 #3
0
        public IndexReference Assign(Var var, bool isGlobal)
        {
            // variableIsGlobal will equal isGlobal if var.VariableType is dynamic. Otherwise, it will equal is var.VariableType global.
            bool variableIsGlobal = var.VariableType == VariableType.Dynamic ? isGlobal : var.VariableType == VariableType.Global;

            if (!var.InExtendedCollection)
            {
                if (var.ID == -1)
                {
                    return(new IndexReference(ArrayBuilder, AssignWorkshopVariable(var.Name, variableIsGlobal)));
                }
                else
                {
                    WorkshopVariable workshopVariable = new WorkshopVariable(variableIsGlobal, var.ID, MetaElement.WorkshopNameFromCodeName(var.Name, NamesTaken(variableIsGlobal)));
                    variableList(variableIsGlobal).Add(workshopVariable);
                    return(new IndexReference(ArrayBuilder, workshopVariable));
                }
            }
            else
            {
                int            index     = NextFreeExtended(variableIsGlobal);
                IndexReference reference = new IndexReference(ArrayBuilder, variableIsGlobal ? global : player, new V_Number(index));
                ExtendedVariableList(variableIsGlobal).Add(new ExtendedVariable(var.Name, reference, index));
                return(reference);
            }
        }
コード例 #4
0
        public static FuncMethod StopChasingVariable(DeltinScript deltinScript) => new FuncMethodBuilder()
        {
            Name          = "StopChasingVariable",
            Documentation = "Stops an in-progress chase of a variable, leaving it at its current value.",
            Parameters    = new CodeParameter[] {
                new VariableParameter("variable", "The variable to stop. Must be a variable defined on the rule level.", VariableType.Dynamic, deltinScript.Types.Any(), new VariableResolveOptions()
                {
                    CanBeIndexed = false, FullVariable = true
                })
            },
            Action = (actionSet, methodCall) => {
                VariableElements elements = ((VariableResolve)methodCall.AdditionalParameterData[0]).ParseElements(actionSet);
                WorkshopVariable variable = ((IndexReference)elements.IndexReference).WorkshopVariable;

                if (variable.IsGlobal)
                {
                    actionSet.AddAction(Element.Part("Stop Chasing Global Variable", variable));
                }
                else
                {
                    actionSet.AddAction(Element.Part("Stop Chasing Player Variable", elements.Target, variable));
                }

                return(null);
            }
        };
コード例 #5
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            VariableElements elements = ((VariableResolve)additionalParameterData[0]).ParseElements(actionSet);
            WorkshopVariable variable = elements.IndexReference.WorkshopVariable;

            Element       destination  = (Element)parameterValues[1];
            Element       duration     = (Element)parameterValues[2];
            IWorkshopTree reevaluation = parameterValues[3];

            if (variable.IsGlobal)
            {
                actionSet.AddAction(Element.Part <A_ChaseGlobalVariableOverTime>(
                                        variable,
                                        destination,
                                        duration,
                                        reevaluation
                                        ));
            }
            else
            {
                actionSet.AddAction(Element.Part <A_ChasePlayerVariableOverTime>(
                                        elements.Target,
                                        variable,
                                        destination,
                                        duration,
                                        reevaluation
                                        ));
            }

            return(null);
        }
コード例 #6
0
        public static IndexedVar AssignVar(VarCollection collection, ScopeGroup scope, string name, bool isGlobal, Node node)
        {
            WorkshopVariable assignedVariable = collection.Assign(name, isGlobal);
            IndexedVar       var = CreateVar(collection.WorkshopArrayBuilder, scope, name, isGlobal, assignedVariable, null, node);

            collection.AllVars.Add(var);
            return(var);
        }
コード例 #7
0
        private WorkshopVariable AssignWorkshopVariable(string name, bool isGlobal)
        {
            int id = NextFreeID(isGlobal);
            WorkshopVariable workshopVariable = new WorkshopVariable(isGlobal, id, WorkshopNameFromCodeName(isGlobal, name));

            variableList(isGlobal).Add(workshopVariable);
            return(workshopVariable);
        }
コード例 #8
0
 public IndexedVar(WorkshopArrayBuilder arrayBuilder, ScopeGroup scopeGroup, string name, bool isGlobal, WorkshopVariable variable, Element[] index, Node node)
     : base(name, scopeGroup, node)
 {
     this.ArrayBuilder = arrayBuilder;
     IsGlobal          = isGlobal;
     Variable          = variable;
     Index             = index;
 }
コード例 #9
0
        private WorkshopVariable AssignWorkshopVariable(string name, bool isGlobal)
        {
            int id = NextFreeID(isGlobal);
            WorkshopVariable workshopVariable = new WorkshopVariable(isGlobal, id, MetaElement.WorkshopNameFromCodeName(name, NamesTaken(isGlobal)));

            variableList(isGlobal).Add(workshopVariable);
            return(workshopVariable);
        }
コード例 #10
0
        public WorkshopVariable Assign(string name, bool isGlobal)
        {
            int index = NextFree(isGlobal);

            WorkshopVariable workshopVariable = new WorkshopVariable(isGlobal, index, WorkshopNameFromCodeName(isGlobal, name));

            UseCollection(isGlobal)[index] = workshopVariable;

            return(workshopVariable);
        }
コード例 #11
0
 private static Element GetRoot(Element targetPlayer, WorkshopVariable variable)
 {
     if (variable.IsGlobal)
     {
         return(Element.Part <V_GlobalVariable>(variable));
     }
     else
     {
         return(Element.Part <V_PlayerVariable>(targetPlayer, variable));
     }
 }
コード例 #12
0
        public void Setup()
        {
            global = AssignWorkshopVariable("_extendedGlobalCollection", true);
            player = AssignWorkshopVariable("_extendedPlayerCollection", false);
            var builder = AssignWorkshopVariable("_arrayBuilder", true);

            IndexReference store = Assign("_arrayBuilderStore", true, true);

            ArrayBuilder = new WorkshopArrayBuilder(builder, store);
            // The store shouldn't require an instance of the WorkshopArrayBuilder, but if for some reason it does uncomment the line below.
            // store.ArrayBuilder = arrayBuilder;
        }
コード例 #13
0
        public static Element GetVariable(Element targetPlayer, WorkshopVariable variable, params Element[] index)
        {
            Element element = GetRoot(targetPlayer, variable);

            if (index != null)
            {
                for (int i = 0; i < index.Length; i++)
                {
                    element = Element.Part <V_ValueInArray>(element, index[i]);
                }
            }
            return(element);
        }
コード例 #14
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            VariableElements elements = ((VariableResolve)additionalParameterData[0]).ParseElements(actionSet);
            WorkshopVariable variable = elements.IndexReference.WorkshopVariable;

            if (variable.IsGlobal)
            {
                actionSet.AddAction(Element.Part <A_StopChasingGlobalVariable>(variable));
            }
            else
            {
                actionSet.AddAction(Element.Part <A_StopChasingPlayerVariable>(elements.Target, variable));
            }

            return(null);
        }
コード例 #15
0
        public static FuncMethod ChaseVariableAtRate(DeltinScript deltinScript) => new FuncMethodBuilder()
        {
            Name          = "ChaseVariableAtRate",
            Documentation = "Gradually modifies the value of a variable at a specific rate.",
            Parameters    = new CodeParameter[] {
                new VariableParameter("variable", "The variable to manipulate. Player variables will chase the event player's variable. Must be a variable defined on the rule level.", VariableType.Dynamic, deltinScript.Types.Any(), new VariableResolveOptions()
                {
                    CanBeIndexed = false, FullVariable = true
                }),
                new CodeParameter("destination", "The value that the variable will eventually reach. The type of this value may be either a number or a vector, through the variable’s existing value must be of the same type before the chase begins. Can use number or vector based values.", NumberOrVector(deltinScript)),
                new CodeParameter("rate", "The amount of change that will happen to the variable’s value each second.", deltinScript.Types.Number()),
                new CodeParameter("reevaluation", "Specifies which of this action's inputs will be continuously reevaluated. This action will keep asking for and using new values from reevaluated inputs.", deltinScript.Types.EnumType("RateChaseReevaluation"))
            },
            Action = (actionSet, methodCall) => {
                VariableElements elements = ((VariableResolve)methodCall.AdditionalParameterData[0]).ParseElements(actionSet);
                WorkshopVariable variable = ((IndexReference)elements.IndexReference).WorkshopVariable;

                Element       destination  = methodCall.Get(1);
                Element       rate         = methodCall.Get(2);
                IWorkshopTree reevaluation = methodCall.ParameterValues[3];

                if (variable.IsGlobal)
                {
                    actionSet.AddAction(Element.Part("Chase Global Variable At Rate",
                                                     variable,
                                                     destination,
                                                     rate,
                                                     reevaluation
                                                     ));
                }
                else
                {
                    actionSet.AddAction(Element.Part("Chase Player Variable At Rate",
                                                     elements.Target,
                                                     variable,
                                                     destination,
                                                     rate,
                                                     reevaluation
                                                     ));
                }

                return(null);
            }
        };
コード例 #16
0
 WorkshopVariable GetExtendedCollection(bool isGlobal)
 {
     if (isGlobal)
     {
         if (_global == null)
         {
             _global = AssignWorkshopVariable("_extendedGlobalCollection", true);
         }
         return(_global);
     }
     else
     {
         if (_player == null)
         {
             _player = AssignWorkshopVariable("_extendedPlayerCollection", false);
         }
         return(_player);
     }
 }
コード例 #17
0
        public static IndexedVar AssignVar(VarCollection collection, ScopeGroup scope, string name, bool isGlobal, WorkshopVariable variable, Node node)
        {
            string workshopName = variable.Name;

            if (workshopName == null)
            {
                workshopName = collection.WorkshopNameFromCodeName(isGlobal, name);
            }

            int id = variable.ID;

            if (id == -1)
            {
                id = collection.NextFree(isGlobal);
            }
            else
            {
                WorkshopVariable assigned = collection.FromID(isGlobal, variable.ID);
                if (assigned != null)
                {
                    throw new SyntaxErrorException("Variable ID '" + variable.ID + "' has already been assigned by '" + assigned.Name + "'.", node.Location);
                }
            }

            WorkshopVariable use = new WorkshopVariable(isGlobal, id, workshopName);

            IndexedVar var = CreateVar(
                collection.WorkshopArrayBuilder,
                scope,
                name,
                isGlobal,
                use,
                null,
                node
                );

            collection.AllVars.Add(var);
            collection.UseCollection(isGlobal)[id] = use;
            return(var);
        }
コード例 #18
0
        public static ElementOrigin GetElementOrigin(Element element)
        {
            bool             isGlobal = false;
            Element          player   = null;
            WorkshopVariable variable = null;

            Element        checking = element;
            List <Element> index    = new List <Element>();

            while (checking != null)
            {
                if (checking is V_GlobalVariable)
                {
                    isGlobal = true;
                    player   = null;
                    variable = (WorkshopVariable)checking.ParameterValues[0];
                    checking = null;
                }
                else if (checking is V_PlayerVariable)
                {
                    isGlobal = false;
                    player   = (Element)checking.ParameterValues[0];
                    variable = (WorkshopVariable)checking.ParameterValues[1];
                    checking = null;
                }
                else if (checking is V_ValueInArray)
                {
                    index.Add((Element)checking.ParameterValues[1]);
                    checking = (Element)checking.ParameterValues[0];
                }
                else
                {
                    return(null);
                }
            }

            return(new ElementOrigin(isGlobal, player, variable, index.ToArray()));
        }
コード例 #19
0
 public WorkshopArrayBuilder(WorkshopVariable constructor, IndexReference store)
 {
     Constructor = constructor;
     Store       = store;
 }
コード例 #20
0
 private static IndexedVar CreateVar(WorkshopArrayBuilder builder, ScopeGroup scope, string name, bool isGlobal, WorkshopVariable variable, Element[] index, Node node)
 {
     if (scope == null || !scope.Recursive)
     {
         return(new IndexedVar(builder, scope, name, isGlobal, variable, index, node));
     }
     else
     {
         return(new RecursiveVar(builder, scope, name, isGlobal, variable, index, node));
     }
 }
コード例 #21
0
 public RecursiveVar(WorkshopArrayBuilder arrayBuilder, ScopeGroup scopeGroup, string name, bool isGlobal, WorkshopVariable variable, Element[] index, Node node)
     : base(arrayBuilder, scopeGroup, name, isGlobal, variable, index, node)
 {
 }
コード例 #22
0
        public static Element[] SetVariable(WorkshopArrayBuilder builder, Element value, Element targetPlayer, WorkshopVariable variable, bool flat2ndDim, params Element[] index)
        {
            if (index == null || index.Length == 0)
            {
                if (variable.IsGlobal)
                {
                    return new Element[] { Element.Part <A_SetGlobalVariable>(variable, value) }
                }
                ;
                else
                {
                    return new Element[] { Element.Part <A_SetPlayerVariable>(targetPlayer, variable, value) }
                };
            }

            if (index.Length == 1)
            {
                if (variable.IsGlobal)
                {
                    return new Element[] { Element.Part <A_SetGlobalVariableAtIndex>(variable, index[0], value) }
                }
                ;
                else
                {
                    return new Element[] { Element.Part <A_SetPlayerVariableAtIndex>(targetPlayer, variable, index[0], value) }
                };
            }

            if (flat2ndDim && index.Length > 2)
            {
                throw new ArgumentOutOfRangeException("index", "Can't set more than 2 dimensions if flat2ndDim is true.");
            }

            if (index.Length == 2 && flat2ndDim)
            {
                Element baseArray      = GetVariable(targetPlayer, variable, index[0]);
                Element baseArrayValue = Element.Part <V_Append>(
                    Element.Part <V_Append>(
                        Element.Part <V_ArraySlice>(
                            baseArray,
                            new V_Number(0),
                            index[1]
                            ),
                        value
                        ),
                    Element.Part <V_ArraySlice>(
                        baseArray,
                        index[1] + 1,
                        new V_Number(Constants.MAX_ARRAY_LENGTH)
                        )
                    );

                return(SetVariable(null, baseArrayValue, targetPlayer, variable, false, index[0]));
            }

            if (builder == null)
            {
                throw new ArgumentNullException("builder", "Can't set multidimensional array if builder is null.");
            }

            List <Element> actions = new List <Element>();

            Element root = GetRoot(targetPlayer, variable);

            // index is 2 or greater
            int dimensions = index.Length - 1;

            // Get the last array in the index path and copy it to variable B.
            actions.AddRange(
                SetVariable(builder, ValueInArrayPath(root, index.Take(index.Length - 1).ToArray()), targetPlayer, builder.Constructor, false)
                );

            // Set the value in the array.
            actions.AddRange(
                SetVariable(builder, value, targetPlayer, builder.Constructor, false, index.Last())
                );

            // Reconstruct the multidimensional array.
            for (int i = 1; i < dimensions; i++)
            {
                // Copy the array to the C variable
                actions.AddRange(
                    builder.Store.SetVariable(GetRoot(targetPlayer, builder.Constructor), targetPlayer)
                    );

                // Copy the next array dimension
                Element array = ValueInArrayPath(root, index.Take(dimensions - i).ToArray());

                actions.AddRange(
                    SetVariable(builder, array, targetPlayer, builder.Constructor, false)
                    );

                // Copy back the variable at C to the correct index
                actions.AddRange(
                    SetVariable(builder, (Element)builder.Store.GetVariable(targetPlayer), targetPlayer, builder.Constructor, false, index[i])
                    );
            }
            // Set the final variable using Set At Index.
            actions.AddRange(
                SetVariable(builder, GetRoot(targetPlayer, builder.Constructor), targetPlayer, variable, false, index[0])
                );
            return(actions.ToArray());
        }
コード例 #23
0
        public static Element[] ModifyVariable(WorkshopArrayBuilder builder, Operation operation, Element value, Element targetPlayer, WorkshopVariable variable, params Element[] index)
        {
            if (index == null || index.Length == 0)
            {
                if (variable.IsGlobal)
                {
                    return new Element[] { Element.Part <A_ModifyGlobalVariable>(variable, EnumData.GetEnumValue(operation), value) }
                }
                ;
                else
                {
                    return new Element[] { Element.Part <A_ModifyPlayerVariable>(targetPlayer, variable, EnumData.GetEnumValue(operation), value) }
                };
            }

            if (index.Length == 1)
            {
                if (variable.IsGlobal)
                {
                    return new Element[] { Element.Part <A_ModifyGlobalVariableAtIndex>(variable, index[0], EnumData.GetEnumValue(operation), value) }
                }
                ;
                else
                {
                    return new Element[] { Element.Part <A_ModifyPlayerVariableAtIndex>(targetPlayer, variable, index[0], EnumData.GetEnumValue(operation), value) }
                };
            }

            if (builder == null)
            {
                throw new ArgumentNullException("builder", "Can't modify multidimensional array if builder is null.");
            }

            List <Element> actions = new List <Element>();

            Element root = GetRoot(targetPlayer, variable);

            // index is 2 or greater
            int dimensions = index.Length - 1;

            // Get the last array in the index path and copy it to variable B.
            actions.AddRange(
                SetVariable(builder, ValueInArrayPath(root, index.Take(index.Length - 1).ToArray()), targetPlayer, builder.Constructor, false)
                );

            // Modify the value in the array.
            actions.AddRange(
                ModifyVariable(builder, operation, value, targetPlayer, builder.Constructor, index.Last())
                );

            // Reconstruct the multidimensional array.
            for (int i = 1; i < dimensions; i++)
            {
                // Copy the array to the C variable
                actions.AddRange(
                    builder.Store.SetVariable(GetRoot(targetPlayer, builder.Constructor), targetPlayer)
                    );

                // Copy the next array dimension
                Element array = ValueInArrayPath(root, index.Take(dimensions - i).ToArray());

                actions.AddRange(
                    SetVariable(builder, array, targetPlayer, builder.Constructor, false)
                    );

                // Copy back the variable at C to the correct index
                actions.AddRange(
                    SetVariable(builder, (Element)builder.Store.GetVariable(targetPlayer), targetPlayer, builder.Constructor, false, index[i])
                    );
            }
            // Set the final variable using Set At Index.
            actions.AddRange(
                SetVariable(builder, GetRoot(targetPlayer, builder.Constructor), targetPlayer, variable, false, index[0])
                );
            return(actions.ToArray());
        }
    }
}
コード例 #24
0
 public IndexReference(WorkshopArrayBuilder arrayBuilder, WorkshopVariable workshopVariable, params Element[] index)
 {
     ArrayBuilder     = arrayBuilder;
     WorkshopVariable = workshopVariable;
     Index            = index;
 }
コード例 #25
0
 public RecursiveIndexReference(WorkshopArrayBuilder arrayBuilder, WorkshopVariable workshopVariable, params Element[] index) : base(arrayBuilder, workshopVariable, index)
 {
 }
コード例 #26
0
 private void Add(WorkshopVariable variable)
 {
     UseCollection(variable.IsGlobal)[variable.ID] = variable;
 }