Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
craig-johnston committed Jul 15, 2024
2 parents 447bd6c + a459a39 commit 374fbd9
Show file tree
Hide file tree
Showing 220 changed files with 6,289 additions and 4,583 deletions.
36 changes: 26 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ dotnet_style_qualification_for_event = false:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_operators = always_for_clarity:none
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
dotnet_style_readonly_field = true:suggestion
Expand All @@ -72,13 +72,20 @@ dotnet_style_prefer_conditional_expression_over_return = false:none
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_style.camel_case_style.capitalization = camel_case
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
# Use camel case for local variable
dotnet_naming_rule.use_camel_case_rule.symbols = use_camel_case
dotnet_naming_rule.use_camel_case_rule.style = camel_case_style
dotnet_naming_rule.use_camel_case_rule.severity = suggestion
dotnet_naming_symbols.use_camel_case.applicable_kinds = parameter,local,local_function

###############################
# C# Coding Conventions #
###############################
Expand All @@ -89,9 +96,9 @@ csharp_style_var_when_type_is_apparent = false:suggestion
# For all else, we prefer non-var but don't enforce it
csharp_style_var_elsewhere = false:none
# Expression-bodied members
csharp_style_expression_bodied_methods = false:suggestion
csharp_style_expression_bodied_constructors = false:suggestion
csharp_style_expression_bodied_operators = false:suggestion
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
Expand All @@ -109,6 +116,7 @@ csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

###############################
# C# Formatting Rules #
###############################
Expand Down Expand Up @@ -139,12 +147,20 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

###############################
# YAFC-CE Code Style #
###############################
# Suppress "IDE0047: Remove unnecessary parentheses." because parentheses improve readability.
dotnet_diagnostic.IDE0047.severity = none

# Suppress IDE0052: Remove unread private members.
# TODO: Unmuting this suggests to delete ProjectPajeView.SearchQuery, which sets off a chain of refactors that need to be tested separately from the code-cleanup PR.
# Issue link: https://github.com/have-fun-was-taken/yafc-ce/issues/181
dotnet_diagnostic.IDE0052.severity = none

# Make fixing formatting mandatory.
dotnet_diagnostic.IDE0055.severity = error

# Disable "IDE0130: Namespace does not match folder structure" because VS Code Cleanup applies it automatically and breaks things.
dotnet_style_namespace_match_folder = false

# Suppress IDE0047: Remove unnecessary parentheses. Parentheses improve readability.
dotnet_diagnostic.IDE0047.severity = none
80 changes: 80 additions & 0 deletions .github/workflows/buildcheck-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
# built on .NET Core.
# To learn how to migrate your existing application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: Debug build check

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:

strategy:
matrix:
configuration: [Debug]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: FactorioCalc.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: Yafc.Model.Tests\Yafc.Model.Tests.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test
78 changes: 78 additions & 0 deletions .github/workflows/buildcheck-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
# built on .NET Core.
# To learn how to migrate your existing application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: Release build check

on:
push:
branches: [ "master" ]

jobs:

build:

strategy:
matrix:
configuration: [Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: FactorioCalc.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: Yafc.Model.Tests\Yafc.Model.Tests.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test
19 changes: 9 additions & 10 deletions CommandLineToolExample/CommandLineToolExample.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp6.0</TargetFramework>
<RootNamespace>YafcCommandLineToolExample</RootNamespace>
<LangVersion>8</LangVersion>
<OutputType>Exe</OutputType>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>YafcCommandLineToolExample</RootNamespace>
<OutputType>Exe</OutputType>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\YAFCmodel\YAFCmodel.csproj" />
<ProjectReference Include="..\YAFCparser\YAFCparser.csproj" />
<ProjectReference Include="..\YAFC\YAFC.csproj" />
<ProjectReference Include="..\Yafc.Model\Yafc.Model.csproj" />
<ProjectReference Include="..\Yafc.Parser\Yafc.Parser.csproj" />
<ProjectReference Include="..\Yafc\Yafc.csproj" />
</ItemGroup>

</Project>
11 changes: 5 additions & 6 deletions CommandLineToolExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using System;
using YAFC;
using YAFC.Model;
using YAFC.Parser;
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
// 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.
string factorioPath = args[0];
ErrorCollector errorCollector = new ErrorCollector();
Expand All @@ -22,7 +21,7 @@ public static void Main(string[] args) {
// 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, new ConsoleProgressReport(), errorCollector, "en", false);
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
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup Label="Normalise stack trace file locations">
<PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=.</PathMap>
</PropertyGroup>
</Project>
44 changes: 34 additions & 10 deletions Docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@

YAFC can be invoked via command line:

`yafc PROJECT_FILE DATA_DIR MODS_DIR [expensive]`
`YAFC [<data-path> [--mods-path <path>] [--project-file <path>] [--expensive]] [--help]`

YAFC can be started without any arguments. However, if arguments other than `--help` are supplied, it is mandatory that the first argument is the path to the data directory of Factorio. The other arguments are optional in any case.

Regardless of whether an option is optional or not, providing paths that do not exist will result in the program printing an error message and exiting.


## Description
- `PROJECT_FILE`: The path to the project file that should be opened.
`<data-path>`: The path of the Factorio's data directory containing the game data (mandatory, if any arguments other than `--help` are supplied)

- `DATA_DIR`: The path to Factorio's data directory containing game data.
`--mods-path <path>`: The path to Factorio's mods directory containing additional game modifications (optional)

- `MODS_DIR`: The path to Factorio's mods directory containing additional game modifications.
`--project-file <path>`: The path to the project file that should be opened (optional)

`--expensive`: Enable expensive recipes (optional)

`--help`: Display a help message and exit

- `expensive`: An optional parameter to use expensive variants of recipes. If provided, the program will use expensive recipes. If not provided, the normal recipe cost is used.

## Examples
These examples assume that Factorio is installed in `C:\Factorio`.
These examples assume that Factorio is installed in `/home/user/Factorio` and the current working directory is `/home/user/YAFC`. A project file is placed at `/home/user/YAFC/my-project.yafc`

#### Starting YAFC without any arguments:
`$ ./YAFC`

This opens the welcome screen, where the user can choose any paths.

#### Starting YAFC with the path to the data directory of Factorio:
`$ ./YAFC ../Factorio/data`

This opens a fresh project and loads the game data from the supplied directory.
Fails if the directory does not exist.

#### Starting YAFC with the paths to the data directory and a project file:
`$ ./YAFC ../Factorio/data --project-file my-project.yafc`

This opens the supplied project and loads the game data from the supplied data directory.
Fails if the directory and/or the project file do not exist.

To open a project file called my_project.yafc located in the current directory:
`yafc my_project.yafc "C:\Factorio\data" "C:\Factorio\mods"`
#### Starting YAFC with the paths to the data & mods directories and a project file:
`$ ./YAFC ../Factorio/data --mods-path Factorio/mods --project-file my-project.yafc`

To open the same project file with expensive recipes:
`yafc my_project.yafc "C:\Factorio\data" "C:\Factorio\mods" expensive`
This opens the supplied project and loads the game data and mods from the supplied data and mods directories. Fails if any of the directories and/or the project file do not exist.
12 changes: 6 additions & 6 deletions Docs/ContributorsGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Here are a couple of things to make your experience in the community more enjoyable.

## Coding
* Please use the same code style as the rest of the codebase. Visual Studio should pick up most of it from `.editorconfig`.
* Please use the same code style as the rest of the codebase. Visual Studio should pick up most of it from `.editorconfig`. You can autoformat the file with the sequence Ctrl+K, Ctrl+D.
* Please prioritize maintainability. Aim for understandable code without dirty hacks.
* Please separate refactoring and the change of behavior into different commits, so it is easier to review the PR.
* Please document the code. If you also can document the existing code, that would be awesome. More documentation helps others to understand the code faster and make the work on YAFC more enjoyable.
* Feel free to put [prefixes](https://www.conventionalcommits.org/en/v1.0.0-beta.2/#summary) in the subjects of your commits -- they might help to browse them later.
* Please separate refactoring from the change of behavior into different commits, so it is easier to review the PR.
* Please document the code. If you can also document the existing code, that would be awesome. More documentation helps others to understand the code faster and make the work on YAFC more enjoyable.
* Feel free to put [prefixes](https://www.conventionalcommits.org/en/v1.0.0-beta.2/#summary) in the subjects of your commits. They might help to browse the commits later.
* If you add a TODO, then please describe the details in the commit message or, ideally, in a github issue. That increases the chances of the TODOs being addressed.
* In the programmers-haven, there is always a free spot for those who write tests.

## Pull Request
* When making a Pull Request, please give some context. For instance, if the PR solves an issue, then you can put a short description of the issue in the PR.
* If there's no corresponding issue, then describe what the problem was and how your PR fixes it. The context, the state without the fix, and with the fix.
* Please provide a short description of your change in the [changelog](https://github.com/have-fun-was-taken/yafc-ce/blob/master/changelog.txt).
* Please provide context in the PR. For instance, if it solves an issue, then you can put a short description of the issue in it.
* Make meaningful commit messages. The easier it is to understand your PR, the faster it will be merged.
* It would be appreciated if you reorganize your commits before the merge -- separate and squash them into logical steps, so they are easier to review and understand. For instance, the fixes to the commits can be squashed into them. The reordering of the commits can be done with the interactive rebase: `git rebase -i head~n`, but please read beforehand on how to do it, so you don't accidentally delete your efforts. If you want to go godlike, feel free to read on `git commit --fixup=` and `git rebase -i --autosquash` ([example](https://stackoverflow.com/questions/3103589/how-can-i-easily-fixup-a-past-commit)). However, it can be the case that the reordering requires very tricky merges, so it's okay to leave them as-is in this case.
Loading

0 comments on commit 374fbd9

Please sign in to comment.