Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# EditorConfig - https://editorconfig.org
# Valkyrie Project Code Style Configuration

root = true

# All files
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# C# files
[*.cs]
indent_size = 4

# Organize usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# this. preferences
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion

# Null-checking preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion

# C# style rules
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:suggestion

# 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_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion

# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion

# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Code block preferences
csharp_prefer_braces = true:suggestion

# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false

# Wrapping preferences
csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true

# XML files
[*.xml]
indent_size = 2

# JSON files
[*.json]
indent_size = 2

# YAML files
[*.{yml,yaml}]
indent_size = 2

# Markdown files
[*.md]
trim_trailing_whitespace = false

# Unity meta files
[*.meta]
indent_size = 2

# Solution files
[*.sln]
indent_style = tab
193 changes: 193 additions & 0 deletions .github/workflows/pull-request-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Pull Request Checks Workflow
#
# This workflow runs automatically on every pull request to the master branch.
# It performs the following checks:
#
# 1. Build Libraries - Compiles C# libraries using MSBuild
# 2. Unity Tests - Runs 867 unit tests in Unity Edit Mode
# 3. Code Quality - Checks code formatting with dotnet format
# 4. Security Scan - Runs CodeQL static analysis for security vulnerabilities
#
# Required Secrets (for Unity Tests job):
# - UNITY_USERNAME: Unity account email
# - UNITY_PASSWORD: Unity account password
# - UNITY_AUTHENTICATOR_KEY: Unity 2FA TOTP secret key

name: Pull Request Checks

on:
pull_request:
branches: [master]

env:
UNITY_VERSION: 2019.4.41f1

jobs:
build-libraries:
name: Build Libraries
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Setup Unity Editor
uses: seinsinnes/[email protected]
with:
unity-version: ${{ env.UNITY_VERSION }}
install-path: "C:/Program Files"

- name: Move Unity to expected location
run: Rename-Item "C:/Program Files/${{ env.UNITY_VERSION }}" Unity

- name: Install NuGet
run: winget install -q Microsoft.NuGet -l "$env:localappdata\NuGet" --accept-source-agreements --accept-package-agreements

- name: Update PATH for NuGet
run: echo "$env:localappdata\NuGet" >> $env:GITHUB_PATH

- name: Restore NuGet packages
run: nuget restore libraries/libraries.sln

- name: Build libraries
run: msbuild libraries/libraries.sln /p:Configuration=Release /nologo

unity-tests:
name: Unity Tests
runs-on: windows-latest
needs: build-libraries

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Setup Unity Editor
uses: seinsinnes/[email protected]
with:
unity-version: ${{ env.UNITY_VERSION }}
install-path: "C:/Program Files"

- name: Activate Unity
uses: kuler90/activate-unity@v1
with:
unity-username: ${{ secrets.UNITY_USERNAME }}
unity-password: ${{ secrets.UNITY_PASSWORD }}
unity-authenticator-key: ${{ secrets.UNITY_AUTHENTICATOR_KEY }}

- name: Move Unity to expected location
run: Rename-Item "C:/Program Files/${{ env.UNITY_VERSION }}" Unity

- name: Install NuGet
run: winget install -q Microsoft.NuGet -l "$env:localappdata\NuGet" --accept-source-agreements --accept-package-agreements

- name: Update PATH for NuGet
run: echo "$env:localappdata\NuGet" >> $env:GITHUB_PATH

- name: Restore NuGet packages
run: nuget restore libraries/libraries.sln

- name: Build libraries
run: msbuild libraries/libraries.sln /p:Configuration=Release /nologo

- name: Remove conflicting UnityEngine.dll
run: |
if (Test-Path "unity/Assets/Plugins/UnityEngine.dll") {
Remove-Item "unity/Assets/Plugins/UnityEngine.dll" -Force
}

- name: Run Unity Edit Mode Tests
run: |
$UnityExe = "C:/Program Files/Unity/Editor/Unity.exe"
$LogFile = "${{ github.workspace }}/test-results.log"
$ResultsFile = "${{ github.workspace }}/test-results.xml"

& $UnityExe -batchmode -nographics -projectPath "${{ github.workspace }}/unity" `
-runTests -testPlatform EditMode `
-testResults $ResultsFile `
-logFile $LogFile

$exitCode = $LASTEXITCODE

if (Test-Path $LogFile) {
Get-Content $LogFile -Tail 100
}

exit $exitCode
continue-on-error: true

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: unity-test-results
path: |
test-results.xml
test-results.log

code-quality:
name: Code Quality
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'

- name: Check code formatting
run: |
dotnet format libraries/ValkyrieTools/ValkyrieTools.csproj --verify-no-changes --verbosity diagnostic || echo "::warning::Code formatting issues found. Run 'dotnet format' locally to fix."
continue-on-error: true

security-scan:
name: Security Scan
runs-on: windows-latest
permissions:
security-events: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: csharp

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Setup Unity Editor
uses: seinsinnes/[email protected]
with:
unity-version: ${{ env.UNITY_VERSION }}
install-path: "C:/Program Files"

- name: Move Unity to expected location
run: Rename-Item "C:/Program Files/${{ env.UNITY_VERSION }}" Unity

- name: Install NuGet
run: winget install -q Microsoft.NuGet -l "$env:localappdata\NuGet" --accept-source-agreements --accept-package-agreements

- name: Update PATH for NuGet
run: echo "$env:localappdata\NuGet" >> $env:GITHUB_PATH

- name: Restore NuGet packages
run: nuget restore libraries/libraries.sln

- name: Build for CodeQL
run: msbuild libraries/libraries.sln /p:Configuration=Release /nologo

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:csharp"
26 changes: 26 additions & 0 deletions unity/Assets/Scripts/IGameProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <summary>
/// Interface for providing game context to classes that need it.
/// This enables testing by allowing mock implementations to be injected.
/// </summary>
public interface IGameProvider
{
/// <summary>
/// Gets the current language code (e.g., "English", "Spanish").
/// </summary>
string CurrentLang { get; }

/// <summary>
/// Gets the current game type (D2E, MoM, IA, or NoGameType).
/// </summary>
GameType GameType { get; }
}

/// <summary>
/// Default implementation that uses the Game singleton.
/// This maintains backwards compatibility with existing code.
/// </summary>
public class DefaultGameProvider : IGameProvider
{
public string CurrentLang => Game.Get()?.currentLang ?? ValkyrieConstants.DefaultLanguage;
public GameType GameType => Game.Get()?.gameType ?? new NoGameType();
}
11 changes: 11 additions & 0 deletions unity/Assets/Scripts/IGameProvider.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading