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(); }
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)); } }
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); } } }
public void Process(Dungeon D) { string dir = Path.Combine(D.BaseDirectory, "GrimLint", "Reports"); Directory.CreateDirectory(dir); string file = Path.Combine(dir, GetReportName() + ".xlsx"); byte[] bytes = Run(D); File.WriteAllBytes(file, bytes); Lint.MsgInfo("Report saved in {0}", file); }
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); } } } }
void LoadLuaAssetsFromFile(string file) { Lint.MsgVerbose("Loading {0}...", file); m_LuaFiles.Push(file); if (file.StartsWith("assets/")) { return; } if (file.StartsWith("mod_assets/")) { file = Path.Combine(m_DungeonDirectory, file.Replace('/', '\\')); } m_Lua.DoFile(file); m_LuaFiles.Pop(); }
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; } } } }
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(); } }
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); } }
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)); }
public void Lua_MapName(string mapName) { ++m_Level; Lint.MsgVerbose("Reading level {0}", m_Level); }
public async Task DoUpdateAsync() { if (IsDisposed) { return; } var buffer = _currentSnapshot; var path = Document.FilePath; // replace with user token var token = _cts.Token; var instance = await FsLintVsPackage.Instance.WithCancellation(token); if (token.IsCancellationRequested) { return; } // this acts as a throttle await Task.Delay(instance.Options.Throttle, token).ConfigureAwait(false); if (token.IsCancellationRequested) { return; } if (ProjectInfo == null) { await instance.JoinableTaskFactory.SwitchToMainThreadAsync(); var solution = instance.Dte.Solution; var project = solution.FindProjectItem(path)?.ContainingProject; if (project == null) { return; } if (instance.SolutionService.GetProjectOfUniqueName(project.UniqueName, out var vsHierarchy) != VSConstants.S_OK) { return; } if (instance.SolutionService.GetGuidOfProject(vsHierarchy, out var guid) != VSConstants.S_OK) { return; } ProjectInfo = new LintProjectInfo(project, solution, guid, vsHierarchy); } if (Configuration == null) { this.Configuration = new[] { Document.FilePath, ProjectInfo.Project.FileName, ProjectInfo.Solution.FileName, Directory.GetParent(ProjectInfo.Solution.FileName).FullName } .Select(Path.GetDirectoryName) .Where(dir => !string.IsNullOrEmpty(dir)) .Select(dir => Path.Combine(dir, "fsharplint.json")) .Where(File.Exists) .Select(Lint.ConfigurationParam.NewFromFile) .FirstOrDefault() ?? Lint.ConfigurationParam.Default; } await Task.Yield(); var lintOpts = new Lint.OptionalLintParameters( cancellationToken: token, configuration: this.Configuration, receivedWarning: null, reportLinterProgress: null); var source = _currentSnapshot.GetText(); var sourceText = SourceText.ofString(source); var parse = instance.Options.TypeCheck ? TryParseAndCheckAsync(path, sourceText, token) : TryParseAsync(path, sourceText, token); var(parseResultsOpt, checkResults) = await parse.ConfigureAwait(false); if (parseResultsOpt == null || parseResultsOpt.Value.ParseHadErrors || token.IsCancellationRequested) { return; } var parseResults = parseResultsOpt.Value; var input = new Lint.ParsedFileInformation(ast: parseResults.ParseTree.Value, source, checkResults); var lintResult = Lint.lintParsedSource(lintOpts, input); if (!lintResult.TryGetSuccess(out var lintWarnings)) { return; } var oldLintingErrors = this.Factory.CurrentSnapshot; var newLintErrors = new LintingErrorsSnapshot(Document, oldLintingErrors.VersionNumber + 1); foreach (var lint in lintWarnings) { var span = RangeToSpan(lint.Details.Range, buffer); newLintErrors.Errors.Add(new LintError(span, lint, ProjectInfo)); } await instance.JoinableTaskFactory.SwitchToMainThreadAsync(); if (token.IsCancellationRequested) { return; } UpdateLintingErrors(newLintErrors); }
public void Init(List<Wire> wires) { for (int i = wires.Count - 1; i >= 0; i--) { Wire wire = wires[i]; wire.Drop(wire.Vector.X); } for (int i = 0; i < GameConfig.HightY; i++) { var lint = new Lint(new IntVector(GameConfig.WidthX, i)); _rightLints.Add(lint); } for (int i = 0; i < GameConfig.HightY; i++) { var lint = new Lint(new IntVector(-1, i)); _leftLints.Add(lint); } for (int i = 1; i < GameConfig.WidthX; i++) { for (int j = 1; j < GameConfig.HightY; j++) { new RevolutionAnchor(new IntVector(i, j)); } } RunAction(MGSequence.Actions(MGDelay.ActionWithDuration(1), MGCallFunc.ActionWithTarget(WireIsChange))); }
public void Init() { for (int i = 0; i < GameConfig.HightY; i++) { for (int j = 0; j < GameConfig.WidthX; j++) { var wire = new Wire(new IntVector(j, -1)); wire.Drop(j); } } for (int i = 0; i < GameConfig.HightY; i++) { var lint = new Lint(new IntVector(GameConfig.WidthX, i)); _rightLints.Add(lint); } for (int i = 0; i < GameConfig.HightY; i++) { var lint = new Lint(new IntVector(-1, i)); _leftLints.Add(lint); } for (int i = 1; i < GameConfig.WidthX; i++) { for (int j = 1; j < GameConfig.HightY; j++) { new RevolutionAnchor(new IntVector(i, j)); } } RunAction(MGSequence.Actions(MGDelay.ActionWithDuration(1), MGCallFunc.ActionWithTarget(WireIsChange))); }