private void MarkModelsFromWallsets() { foreach (Definition def in D.Assets.GetAllDefs(DefinitionType.Wallset)) { var models = def.FlattenedValues.OfType <string>() .Where(f => !string.IsNullOrWhiteSpace(f)) .Where(f => f.EndsWith(".fbx", StringComparison.InvariantCultureIgnoreCase) && (!f.StartsWith("assets/", StringComparison.InvariantCultureIgnoreCase))) .Select(f => f.Replace(".fbx", ".model")); foreach (string fbxc in models) { string fbx = fbxc.ToLower(); if (m_Models.ContainsKey(fbx)) { m_Models[fbx].MarkUsedByWallset(def.Name); if (fbxc != m_Models[fbx].NameRealCase) { Lint.MsgWarn("[{0}]: Case-mismatch of filenames in wallset {1} for model {2}.", def.DeclaringFile, def.Name, m_Models[fbx].NameRealCase); } } else { Lint.MsgWarn("[{0}]: Wallset {1} refers to model {2} which was not found on disk", def.DeclaringFile, def.Name, fbx); } } } }
public Entity PostCreate(Assets assets) { if (Id.StartsWith(Name + "_")) { int dummy; string id = Id.Substring(Name.Length + 1); KnownName = !(int.TryParse(id, out dummy)); } else { KnownName = true; } Asset A = assets.Get(Name); if (A != null) { Class = A.Class; ItemClass = A.ItemClass; } else { Class = EntityClass.Unknown; ItemClass = 0; Lint.MsgWarn("Can't find asset {0} for entity {1}", Name, this); } return(this); }
private void AddAllObjectsFromDeclarations() { foreach (Definition def in D.Assets.GetAllDefs(DefinitionType.Object)) { var models = GetModelsForDef(def) .Where(f => !string.IsNullOrWhiteSpace(f)) .Where(f => f.EndsWith(".fbx", StringComparison.InvariantCultureIgnoreCase) && (!f.StartsWith("assets/", StringComparison.InvariantCultureIgnoreCase))) .Select(f => f.Replace(".fbx", ".model")); foreach (string fbxc in models) { string fbx = fbxc.ToLower(); if (m_Models.ContainsKey(fbx)) { m_Objects.AddMulti(def.Name, m_Models[fbx]); m_Models[fbx].ObjectNamesUsingThisModel.Add(def.Name); if (fbxc != m_Models[fbx].NameRealCase) { Lint.MsgWarn("[{0}]: Case-mismatch of filenames in object {1} for model {2}.", def.DeclaringFile, def.Name, m_Models[fbx].NameRealCase); } } else { Lint.MsgWarn("[{0}]: Object {1} refers to model {2} which was not found on disk", def.DeclaringFile, def.Name, fbx); } } } }
public void Warning(Entity E, string format, params object[] args) { if (ShouldReport(E)) { Lint.MsgWarn("{0}-{1}: {2}", GetRuleName(), E, string.Format(format, args)); } }
public void CreateReverseConnectors() { foreach (Entity E in EntitiesById.Values) { foreach (Connector C in E.Connectors) { if (EntitiesById.ContainsKey(C.Target)) { Entity E1 = EntitiesById[C.Target]; E1.ReverseConnectors.Add(C); } else { Lint.MsgWarn("Can't find entity {0} referenced by connector of {1}", C.Target, E); } } } }
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; } } } }
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); }
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)); }