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(); }
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)); }