示例#1
0
        public void Load(Dungeon D)
        {
            this.D = D;

            LuaLineReader reader = new LuaLineReader(D.DungeonLuaFile);

            while (true)
            {
                string line = reader.Get();

                if (line == null)
                {
                    break;
                }

                try
                {
                    LoadLine(line, reader);
                }
                catch (EndOfFileException)
                {
                    Lint.MsgErr("FATAL: Unexpected end of file.");
                    break;
                }
            }

            Lint.MsgVerbose("{0} entities loaded", D.EntitiesById.Values.Count);

            D.CreateReverseConnectors();
        }
示例#2
0
文件: Rule.cs 项目: xanathar/grimlint
 public void Error(Entity E, string format, params object[] args)
 {
     if (ShouldReport(E))
     {
         Lint.MsgErr("{0}-{1}: {2}", GetRuleName(), E, string.Format(format, args));
     }
 }
示例#3
0
        public void CreateAssetsFromDefs()
        {
            var defs = GetAllDefs(DefinitionType.Object);

            foreach (var def in defs)
            {
                string clss       = def.Properties.Find("class") as string;
                string baseObject = def.Properties.Find("baseObject") as string;
                if (clss != null)
                {
                    EntityClass ec;
                    if (Enum.TryParse <EntityClass>(clss, out ec))
                    {
                        Asset A = new Asset()
                        {
                            Name  = def.Name,
                            Class = ec,
                        };
                        m_Assets[A.Name] = A;
                    }
                    else
                    {
                        Lint.MsgErr("[{0}]: Object {1} is defined with unknown class {2}", def.DeclaringFile, def.Name, clss);
                    }
                }
                else if (baseObject != null)
                {
                    Asset A = this.Get(baseObject);
                    if (A == null)
                    {
                        Lint.MsgWarn("[{0}]: Object {1} is a clone of not found object {2}", def.DeclaringFile, def.Name, baseObject);
                    }
                    else
                    {
                        A                = new Asset(A);
                        A.Name           = def.Name;
                        m_Assets[A.Name] = A;
                    }
                }
            }
        }
示例#4
0
        public Connector(string source, string addConnMethodCallParamsCode)
        {
            Source = source;
            string origcode = addConnMethodCallParamsCode;

            addConnMethodCallParamsCode = addConnMethodCallParamsCode.Replace("addConnector(", "");
            addConnMethodCallParamsCode = addConnMethodCallParamsCode.Replace(")", "");
            addConnMethodCallParamsCode = addConnMethodCallParamsCode.Replace("\"", "");

            string[] pieces = addConnMethodCallParamsCode.Split(',');

            if (pieces.Length != 3)
            {
                Lint.MsgErr("error parsing connector in source {0} - {1}", Source, origcode);
            }
            else
            {
                SourceAction = pieces[0].Trim();
                Target       = pieces[1].Trim();
                TargetAction = pieces[2].Trim();
            }
        }
示例#5
0
        public void AddEntity(Entity E, int level)
        {
            if (EntitiesById.ContainsKey(E.Id))
            {
                Lint.MsgErr("Duplicate id: {0}", E.Id);
                return;
            }

            EntitiesById.Add(E.Id, E);

            AllEntities.Add(E);
            EntitiesByLevel.AddMulti(level, E);
            EntitiesByName.AddMulti(E.Name, E);
            EntitiesByClass.AddMulti(E.Class, E);

            foreach (Entity e in E.Items)
            {
                AllEntities.Add(e);
                EntitiesByLevel.AddMulti(level, e);
                EntitiesByName.AddMulti(e.Name, e);
                EntitiesByClass.AddMulti(e.Class, e);
            }
        }
示例#6
0
        private static string ParseMethod(Entity E, string mcall, LuaLineReader reader, Assets assets)
        {
            if (string.IsNullOrEmpty(mcall))
            {
                return(null);
            }

            if (mcall[0] == ':')
            {
                mcall = mcall.Substring(1);
            }

            if (mcall.StartsWith("setSource"))
            {
                E.HintClass(EntityClass.ScriptEntity);

                while (!mcall.EndsWith(")"))
                {
                    mcall = reader.GetOrThrow(true);
                }
            }
            else if (mcall.StartsWith("set"))
            {
                string   tcall  = mcall.Substring(3, mcall.Length - 4);
                string[] pieces = tcall.Split('(');
                if (pieces.Length != 2)
                {
                    Lint.MsgErr("Can't parse: :{0}", mcall);
                }
                else
                {
                    E.Properties[pieces[0]] = pieces[1].Replace("\"", "").Replace(")", "").Replace("(", "").Trim();
                }
            }
            else if (mcall.StartsWith("addConnector"))
            {
                // addConnector("activate", "id", "open")
                E.Connectors.Add(new Connector(E.Id, mcall));
            }
            else if (mcall.StartsWith("addItem(spawn("))
            {
                if (mcall.Contains(":addItem"))
                {
                    string[] calls = mcall.Split(new string[] { ":", ")spaw" }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string call in calls)
                    {
                        if (call.StartsWith("n("))
                        {
                            return("spaw" + call);
                        }
                        else
                        {
                            string thiscall = call;
                            if (!thiscall.EndsWith(")"))
                            {
                                thiscall += ")";
                            }
                            ParseMethod(E, thiscall.Trim(), reader, assets);
                        }
                    }
                }
                else
                {
                    string item = mcall.Substring("addItem(spawn(\"".Length, mcall.Length - "addItem(spawn(\"".Length - 1).Replace("(", "").Replace(")", "").Replace("\"", "").Trim();
                    Entity S    = new Entity()
                    {
                        Name = item
                    };
                    S.SetContainer(E, E.Items.Count + 1);
                    S.PostCreate(assets);
                    E.Items.Add(S);
                }
            }
            else if (mcall.StartsWith("addTrapDoor"))
            {
                E.HintClass(EntityClass.Pit);
                E.HasTrapDoor = true;
            }
            else if (mcall.StartsWith("addPullChain"))
            {
                E.HintClass(EntityClass.Door);
                E.HasPullChain = true;
            }
            else if (mcall.StartsWith("addTorch"))
            {
                E.HintClass(EntityClass.TorchHolder);
                E.HasTorch = true;
            }
            else if (mcall.StartsWith("activate"))
            {
                E.IsActive = true;
            }
            else if (mcall.StartsWith("deactivate"))
            {
                E.IsActive = false;
            }
            else
            {
                Lint.MsgWarn("Unknown method: {0}", mcall);
            }

            return(null);
        }
示例#7
0
        public static Tuple <Entity, string> CreateEntity(int level, string line, LuaLineReader reader, Assets assets)
        {
            Entity E = new Entity();

            string sline = line.Substring("spawn(".Length, line.Length - ("spawn(".Length + 1));

            string[] parts    = sline.Split(',');
            string   lastLine = null;

            if (parts.Length != 5)
            {
                Lint.MsgErr("Error parsing line:{0}", line);
            }

            E.Id = parts[4].Replace("\"", "").Trim();

            E.Level  = level;
            E.X      = int.Parse(parts[1]);
            E.Y      = int.Parse(parts[2]);
            E.Facing = int.Parse(parts[3]);
            E.Name   = parts[0].Replace("\"", "").Trim();
            Asset A = assets.Get(E.Name);

            if (A != null)
            {
                E.Class     = A.Class;
                E.ItemClass = A.ItemClass;
            }
            else
            {
                E.Class     = EntityClass.Unknown;
                E.ItemClass = 0;
                Lint.MsgWarn("Can't find asset {0} for entity {1}", E.Name, E);
            }

            bool dontRollback = false;

            try
            {
                while (true)
                {
                    string mcall = reader.Get();

                    if (mcall == null)
                    {
                        dontRollback = true;
                        break;
                    }

                    if (mcall.StartsWith(":"))
                    {
                        lastLine = ParseMethod(E, mcall, reader, assets);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            finally
            {
                if (!dontRollback)
                {
                    reader.RollBack();
                }
            }

            return(new Tuple <Entity, string>(E.PostCreate(assets), lastLine));
        }