Example #1
0
        int FromVariableIndexName(MegaloScriptVariableType type, string name)
        {
            int id = TypeExtensionsBlam.IndexOfByPropertyNotFoundResult;

            switch (type)
            {
            case MegaloScriptVariableType.Numeric:  id = MegaloScriptModel.FindNameIndex(Numerics, name); break;

            case MegaloScriptVariableType.Timer:    id = MegaloScriptModel.FindNameIndex(Timers, name); break;

            case MegaloScriptVariableType.Team:             id = MegaloScriptModel.FindNameIndex(Teams, name); break;

            case MegaloScriptVariableType.Player:   id = MegaloScriptModel.FindNameIndex(Players, name); break;

            case MegaloScriptVariableType.Object:   id = MegaloScriptModel.FindNameIndex(Objects, name); break;

            default: throw new KSoft.Debug.UnreachableException(type.ToString());
            }

            if (id == TypeExtensionsBlam.IndexOfByPropertyNotFoundResult)
            {
                throw new KeyNotFoundException(string.Format("Couldn't find {0} {1} variable named {2}",
                                                             SetType, type, name));
            }

            return(id);
        }
Example #2
0
        internal bool VarIndexIsValid(MegaloScriptVariableType type, int index)
        {
            switch (type)
            {
            case MegaloScriptVariableType.Numeric: return(index < Numerics.Count);

            case MegaloScriptVariableType.Timer: return(index < Timers.Count);

            case MegaloScriptVariableType.Team: return(index < Teams.Count);

            case MegaloScriptVariableType.Player: return(index < Players.Count);

            case MegaloScriptVariableType.Object: return(index < Objects.Count);

            default: throw new KSoft.Debug.UnreachableException(type.ToString());
            }
        }
Example #3
0
        string ToVariableIndexName(MegaloScriptVariableType type, int index)
        {
            if (index < 0 || !VarIndexIsValid(type, index))
            {
                throw new System.IO.InvalidDataException(string.Format("#{0} is not a valid {1}.{2} variable index",
                                                                       index.ToString(), SetType.ToString(), type.ToString()));
            }

            switch (type)
            {
            case MegaloScriptVariableType.Numeric: return(Numerics[index].CodeName);

            case MegaloScriptVariableType.Timer: return(Timers[index].CodeName);

            case MegaloScriptVariableType.Team: return(Teams[index].CodeName);

            case MegaloScriptVariableType.Player: return(Players[index].CodeName);

            case MegaloScriptVariableType.Object: return(Objects[index].CodeName);

            default: throw new KSoft.Debug.UnreachableException(type.ToString());
            }
        }
Example #4
0
        static string ToVariableIndexName(MegaloScriptModel model, MegaloScriptVariableSet varSet, MegaloScriptVariableType varType, int index, bool supportNone)
        {
            if (index.IsNone())
            {
                if (supportNone)
                {
                    return(MegaloScriptModel.kIndexNameNone);
                }
                else
                {
                    throw new System.IO.InvalidDataException(string.Format("Encountered a {0}.{1} variable reference that was NONE, where NONE isn't supported",
                                                                           varSet.ToString(), varType.ToString()));
                }
            }

            return(model[varSet].ToVariableIndexName(varType, index));
        }