Пример #1
0
    public bool ArgumentMatchesType(VsnArgument arg, VsnArgType type)
    {
        switch (type)
        {
        case VsnArgType.numberArg:
            return(arg.GetType() == typeof(VsnNumber) ||
                   arg.GetType() == typeof(VsnReference));

        case VsnArgType.stringArg:
            return(arg.GetType() == typeof(VsnString) ||
                   arg.GetType() == typeof(VsnReference));

        case VsnArgType.booleanArg:
            return(arg.GetType() == typeof(VsnBoolean) ||
                   arg.GetType() == typeof(VsnReference));

        case VsnArgType.operatorArg:
            return(arg.GetType() == typeof(VsnOperator));

        case VsnArgType.referenceArg:
            return(arg.GetType() == typeof(VsnReference) ||
                   arg.GetType() == typeof(VsnMetaReference));
        }
        return(false);
    }
    private bool CompareVariables(VsnArgument op1, VsnArgument op2)
    {
        /// TODO: also implement when the two variables are different types
        /// or when they're both strings

        return(CompareFloats(op1.GetNumberValue(), op2.GetNumberValue()));
    }
Пример #3
0
 public override void Execute()
 {
     VsnArgument[] newArgs = new VsnArgument[args.Length - 1];
     for (int i = 1; i < args.Length; i++)
     {
         newArgs[i - 1] = args[i];
     }
     VsnController.instance.GotoVSNScript(args[0].GetStringValue(), newArgs);
 }
        public override void Execute()
        {
            VsnArgument variableName = args[0];
            VsnArgument valueToAdd   = args[1];

            float oldValue = VsnSaveSystem.GetFloatVariable(variableName.GetReference());
            float newValue = oldValue + valueToAdd.GetNumberValue();

            VsnSaveSystem.SetVariable(variableName.GetReference(), newValue);
            VsnSaveSystem.Save(0);
        }
    public List <VsnCommand> ParseVSNCommands(string[] lines)
    {
        List <VsnCommand> vsnCommandsFromScript = new List <VsnCommand>();

        int commandNumber = 0;

        for (int i = 0; i < lines.Length; i++)
        {
            string line = lines[i].TrimStart();

            if (line == "\r" || String.IsNullOrEmpty(line))
            {
                continue;
            }

            List <VsnArgument> vsnArguments = new List <VsnArgument>();

            string commandName = Regex.Match(line, "^([\\w\\-]+)").Value;

            MatchCollection valuesMatch = Regex.Matches(line, "[^\\s\"']+|\"[^\"]*\"|'[^']*'");

            List <string> args = new List <string>();

            foreach (Match match in valuesMatch)
            {
                args.Add(match.Value);
            }

            args.RemoveAt(0); // Removes the first match, which is the "commandName"

            foreach (string arg in args)
            {
                VsnArgument vsnArgument = ParseArgument(arg);
                vsnArguments.Add(vsnArgument);
            }

            VsnCommand vsnCommand = InstantiateVsnCommand(commandName, vsnArguments);
            if (vsnCommand != null)
            {
                if (commandName == "waypoint")
                {
                    RegisterWaypoint(new VsnWaypoint(vsnArguments[0].GetReference(), commandNumber));
                }

                vsnCommand.commandIndex = commandNumber;
                vsnCommand.fileLineId   = i + 1;
                commandNumber++;
                vsnCommandsFromScript.Add(vsnCommand);
            }
        }

        return(vsnCommandsFromScript);
    }
    public bool EvaluateComparison(VsnArgument first, VsnArgument second)
    {
        if ((first.GetType() == typeof(VsnNumber) && second.GetType() == typeof(VsnNumber)) ||
            (first.GetType() == typeof(VsnReference) && second.GetType() == typeof(VsnNumber)) ||
            (first.GetType() == typeof(VsnNumber) && second.GetType() == typeof(VsnReference)))
        {
            return(CompareFloats(first.GetNumberValue(), second.GetNumberValue()));
        }

        if ((first.GetType() == typeof(VsnString) && second.GetType() == typeof(VsnString)) ||
            (first.GetType() == typeof(VsnReference) && second.GetType() == typeof(VsnString)) ||
            (first.GetType() == typeof(VsnString) && second.GetType() == typeof(VsnReference)))
        {
            return(CompareStrings(first.GetStringValue(), second.GetStringValue()));
        }

        return(CompareVariables(first, second));
    }