-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (61 loc) · 2.42 KB
/
Program.cs
File metadata and controls
65 lines (61 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Globalization;
using System.Threading;
using YAFC;
using YAFC.Model;
using YAFC.Parser;
namespace CommandLineToolExample
{
// If you wish to embed yafc or make a command-line tool using YAFC, here is an example on how to do that
// However, I can't make any promises about not changing signatures
public static class Program
{
public static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Pass FactorioData path as command-line argument");
return;
}
YafcLib.Init();
YafcLib.RegisterDefaultAnalysis(); // Register analysis to get cost, milestones, accessibility, etc information. Skip if you just need data.
var factorioPath = args[0];
var errorCollector = new ErrorCollector();
Project project;
try
{
// Load YAFC project.
// Empty project path loads default project (with one empty page).
// Project is irrelevant if you just need data, but you need it to perform sheet calculations
// Set to not render any icons
project = FactorioDataSource.Parse(factorioPath, "", "", false, false, new ConsoleProgressReport(), errorCollector, "en", false);
}
catch (Exception ex)
{
// Critical errors that make project un-loadable will be thrown as exceptions
Console.Error.WriteException(ex);
return;
}
if (errorCollector.severity != ErrorSeverity.None)
{
// Some non-critical errors were found while loading project, for example missing recipe or analysis warnings
foreach (var (error, _) in errorCollector.GetArrErrors())
{
Console.Error.WriteLine(error);
}
}
// To confirm project loading, enumerate all objects
foreach (var obj in Database.objects.all)
{
Console.WriteLine(obj.locName);
}
}
private class ConsoleProgressReport : IProgress<(string, string)>
{
public void Report((string, string) value)
{
Console.WriteLine(value.Item1 +" - " + value.Item2);
}
}
}
}