Ejemplo n.º 1
0
        private void LoadLine(string line, LuaLineReader reader)
        {
            if (line.StartsWith("mapName("))
            {
                ++m_CurLevel;
                Lint.MsgVerbose("Reading level {0}", m_CurLevel);
            }
            else if (line.StartsWith("setWallSet") || line.StartsWith("playStream"))
            {
                return;
            }
            else if (line.StartsWith("mapDesc([["))
            {
                while (reader.GetOrThrow() != "]])")
                {
                    ;                                                  // skip map
                }
            }
            else if (line.StartsWith("spawn"))
            {
                Tuple <Entity, string> T = LineEntityReader.CreateEntity(m_CurLevel, line, reader, D.Assets);

                D.AddEntity(T.Item1, m_CurLevel);

                if (T.Item2 != null)
                {
                    LoadLine(T.Item2, reader);
                }
            }
        }
Ejemplo n.º 2
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);
        }