mirror of
				https://github.com/9ParsonsB/Pulsar.git
				synced 2025-11-03 23:36:42 -05:00 
			
		
		
		
	[Explorer] Default + Custom Criteria improvements (#130)
* [Explorer] Default + Custom Criteria improvements For Custom Criteria: * If a custom criteria throws an error or fails to parse/load, Core no longer disables custom criteria entirely -- it now disables the problematic criteria until you update the custom criteria file and trigger a new journal/re-read (which reloads the source file). For Default Criteria: * Adds landable status of the body triggering the Close Ring/Belt proximity. (Requested in Discord somewhere.) * Adds the triggering ring name to the Wide Ring criteria. (I believe also requested, can't remember now.)
This commit is contained in:
		@@ -12,6 +12,7 @@ namespace Observatory.Explorer
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        private Lua LuaState;
 | 
					        private Lua LuaState;
 | 
				
			||||||
        private Dictionary<String,LuaFunction> CriteriaFunctions;
 | 
					        private Dictionary<String,LuaFunction> CriteriaFunctions;
 | 
				
			||||||
 | 
					        private Dictionary<string, string> CriteriaWithErrors = new();
 | 
				
			||||||
        Action<Exception, String> ErrorLogger;
 | 
					        Action<Exception, String> ErrorLogger;
 | 
				
			||||||
        private uint ScanCount;
 | 
					        private uint ScanCount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -180,6 +181,7 @@ namespace Observatory.Explorer
 | 
				
			|||||||
            #endregion
 | 
					            #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            CriteriaFunctions.Clear();
 | 
					            CriteriaFunctions.Clear();
 | 
				
			||||||
 | 
					            CriteriaWithErrors.Clear();
 | 
				
			||||||
            var criteria = File.Exists(criteriaPath) ? File.ReadAllLines(criteriaPath) : Array.Empty<string>();
 | 
					            var criteria = File.Exists(criteriaPath) ? File.ReadAllLines(criteriaPath) : Array.Empty<string>();
 | 
				
			||||||
            StringBuilder script = new();
 | 
					            StringBuilder script = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -260,8 +262,8 @@ namespace Observatory.Explorer
 | 
				
			|||||||
                StringBuilder errorDetail = new();
 | 
					                StringBuilder errorDetail = new();
 | 
				
			||||||
                errorDetail.AppendLine("Error Reading Custom Criteria File:")
 | 
					                errorDetail.AppendLine("Error Reading Custom Criteria File:")
 | 
				
			||||||
                    .AppendLine(originalScript)
 | 
					                    .AppendLine(originalScript)
 | 
				
			||||||
                    .AppendLine("NOTE: Custom criteria processing has been disabled to prevent further errors.");
 | 
					                    .AppendLine("To correct this problem, make changes to the Lua source file, save it and either re-run read-all or scan another body. It will be automatically reloaded."); ErrorLogger(e, errorDetail.ToString());
 | 
				
			||||||
                ErrorLogger(e, errorDetail.ToString());
 | 
					                CriteriaFunctions.Clear(); // Don't use partial parse.
 | 
				
			||||||
                throw new CriteriaLoadException(e.Message, originalScript);
 | 
					                throw new CriteriaLoadException(e.Message, originalScript);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -273,6 +275,9 @@ namespace Observatory.Explorer
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            foreach (var criteriaFunction in CriteriaFunctions)
 | 
					            foreach (var criteriaFunction in CriteriaFunctions)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
					                // Skip criteria which have previously thrown an error. We can't remove them from the dictionary while iterating it. 
 | 
				
			||||||
 | 
					                if (CriteriaWithErrors.ContainsKey(criteriaFunction.Key)) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var scanList = scanHistory[scan.SystemAddress].Values.ToList();
 | 
					                var scanList = scanHistory[scan.SystemAddress].Values.ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                int bioSignals;
 | 
					                int bioSignals;
 | 
				
			||||||
@@ -326,15 +331,23 @@ namespace Observatory.Explorer
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                catch (NLua.Exceptions.LuaScriptException e)
 | 
					                catch (NLua.Exceptions.LuaScriptException e)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    settings.EnableCustomCriteria = false;
 | 
					 | 
				
			||||||
                    results.Add((e.Message, scan.Json, false));
 | 
					                    results.Add((e.Message, scan.Json, false));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    StringBuilder errorDetail = new();
 | 
					                    StringBuilder errorDetail = new();
 | 
				
			||||||
                    errorDetail.AppendLine($"while processing custom criteria '{criteriaFunction.Key}' on scan:")
 | 
					                    errorDetail.AppendLine($"while processing custom criteria '{criteriaFunction.Key}' on scan:")
 | 
				
			||||||
                        .AppendLine(scan.Json)
 | 
					                        .AppendLine(scan.Json)
 | 
				
			||||||
                        .AppendLine("NOTE: Custom criteria processing has been disabled to prevent further errors.");
 | 
					                        .AppendLine("To correct this problem, make changes to the Lua source file, save it and either re-run read-all or scan another body. It will be automatically reloaded.");
 | 
				
			||||||
                    ErrorLogger(e, errorDetail.ToString());
 | 
					                    ErrorLogger(e, errorDetail.ToString());
 | 
				
			||||||
                    break;
 | 
					                    CriteriaWithErrors.Add(criteriaFunction.Key, e.Message + Environment.NewLine + errorDetail.ToString());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Remove any erroring criteria. They will be repopulated next time the file is parsed.
 | 
				
			||||||
 | 
					            if (CriteriaWithErrors.Count > 0)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                foreach (var criteriaKey in CriteriaWithErrors.Keys)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    if (CriteriaFunctions.ContainsKey(criteriaKey)) CriteriaFunctions.Remove(criteriaKey);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -104,8 +104,9 @@ namespace Observatory.Explorer
 | 
				
			|||||||
                        if (separation < scan.Radius * 10)
 | 
					                        if (separation < scan.Radius * 10)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            var ringTypeName = ring.Name.Contains("Belt") ? "Belt" : "Ring";
 | 
					                            var ringTypeName = ring.Name.Contains("Belt") ? "Belt" : "Ring";
 | 
				
			||||||
 | 
					                            var isLandable = scan.Landable ? ", Landable" : "";
 | 
				
			||||||
                            results.Add($"Close {ringTypeName} Proximity",
 | 
					                            results.Add($"Close {ringTypeName} Proximity",
 | 
				
			||||||
                                $"Orbit: {scan.SemiMajorAxis / 1000:N0}km, Radius: {scan.Radius / 1000:N0}km, Distance from {ringTypeName.ToLower()}: {separation / 1000:N0}km");
 | 
					                                $"Orbit: {scan.SemiMajorAxis / 1000:N0}km, Radius: {scan.Radius / 1000:N0}km, Distance from {ringTypeName.ToLower()}: {separation / 1000:N0}km{isLandable}");
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -130,7 +131,8 @@ namespace Observatory.Explorer
 | 
				
			|||||||
                    var ringWidth = ring.OuterRad - ring.InnerRad;
 | 
					                    var ringWidth = ring.OuterRad - ring.InnerRad;
 | 
				
			||||||
                    if (ringWidth > scan.Radius * 5)
 | 
					                    if (ringWidth > scan.Radius * 5)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        results.Add("Wide Ring", $"Width: {ringWidth / 299792458:N2}Ls / {ringWidth / 1000:N0}km, Parent Radius: {scan.Radius / 1000:N0}km");
 | 
					                        var ringName = ring.Name.Replace(scan.BodyName, "").Trim();
 | 
				
			||||||
 | 
					                        results.Add("Wide Ring", $"{ringName}: Width: {ringWidth / 299792458:N2}Ls / {ringWidth / 1000:N0}km, Parent Radius: {scan.Radius / 1000:N0}km");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -188,7 +188,6 @@ namespace Observatory.Explorer
 | 
				
			|||||||
                                Details = e.OriginalScript
 | 
					                                Details = e.OriginalScript
 | 
				
			||||||
                            };
 | 
					                            };
 | 
				
			||||||
                            ObservatoryCore.AddGridItem(ExplorerWorker, exceptionResult);
 | 
					                            ObservatoryCore.AddGridItem(ExplorerWorker, exceptionResult);
 | 
				
			||||||
                            ExplorerWorker.settings.EnableCustomCriteria = false;
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        
 | 
					                        
 | 
				
			||||||
                        CriteriaLastModified = fileModified;
 | 
					                        CriteriaLastModified = fileModified;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user