diff --git a/.github/scripts/build-and-pack-nuget.sh b/.github/scripts/build-and-pack-nuget.sh
index 2bfc0501..a19f08b8 100644
--- a/.github/scripts/build-and-pack-nuget.sh
+++ b/.github/scripts/build-and-pack-nuget.sh
@@ -31,8 +31,8 @@ can_build_project() {
# Get the dependencies - dotnet list outputs them with paths like ..\ProjectName\ProjectName.csproj
# We need to extract just the project name from the filename
local deps=$(dotnet list "$project" reference 2>/dev/null | grep '\.csproj$' | while read -r line; do
- # Remove everything up to the last backslash, then remove .csproj extension
- echo "$line" | sed 's/.*\\//' | sed 's/\.csproj$//'
+ # Remove everything up to the last slash (forward or back), then remove .csproj extension
+ echo "$line" | sed 's/.*[\\\/]//' | sed 's/\.csproj$//'
done | tr '\n' ' ')
for dep in $deps; do
@@ -72,7 +72,7 @@ while [ -n "$REMAINING_PROJECTS" ] && [ $ITERATION -lt $MAX_ITERATIONS ]; do
echo "$STILL_REMAINING" | tr ';' '\n' | while read -r p; do
if [ -n "$p" ]; then
echo " - $(basename $(dirname "$p"))"
- echo " Dependencies: $(dotnet list "$p" reference 2>/dev/null | grep -E "^\s+.*\.csproj" | sed 's/.*\///' | sed 's/\.csproj.*//' | tr '\n' ' ')"
+ echo " Dependencies: $(dotnet list "$p" reference 2>/dev/null | grep -E "^\s+.*\.csproj" | sed 's/.*[\\\/]//' | sed 's/\.csproj.*//' | tr '\n' ' ')"
fi
done
echo "Already built: $BUILT_PROJECTS"
@@ -159,10 +159,10 @@ while [ -n "$REMAINING_PROJECTS" ] && [ $ITERATION -lt $MAX_ITERATIONS ]; do
dotnet restore "$project" -p:Configuration=Release --verbosity minimal --force --no-cache
# Build the project
- dotnet build "$project" --configuration Release --no-restore --verbosity minimal
+ dotnet build "$project" -p:PACK=true -p:WarningLevel=0 -p:RunAnalyzers=false -p:SuppressTfmSupportBuildWarnings=true --configuration Release --no-restore --verbosity minimal
# Pack directly to artifacts with project name folder structure for proper NuGet feed
- dotnet pack "$project" --configuration Release --no-build --output "./artifacts/${PROJECT_NAME}" -p:PACK=true --verbosity minimal
+ dotnet pack "$project" -p:PACK=true --configuration Release --no-build --output "./artifacts/${PROJECT_NAME}" --verbosity minimal
fi
BUILT_PROJECTS="${BUILT_PROJECTS}${PROJECT_NAME};"
diff --git a/Directory.Build.props b/Directory.Build.props
index ae833a36..cfc5905e 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -6,7 +6,7 @@
-
+
diff --git a/Directory.Packages.props b/Directory.Packages.props
index b4499b70..eaf391c7 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -4,12 +4,14 @@
+
+
@@ -30,21 +32,21 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
+
\ No newline at end of file
diff --git a/NuGet.config b/NuGet.config
index 8a2bf809..d4b82f99 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -16,9 +16,9 @@
-
+
diff --git a/docs/changelogs/War3Net.Build.Core.changelog.md b/docs/changelogs/War3Net.Build.Core.changelog.md
index 806477fd..95d5542a 100644
--- a/docs/changelogs/War3Net.Build.Core.changelog.md
+++ b/docs/changelogs/War3Net.Build.Core.changelog.md
@@ -1,5 +1,13 @@
# War3Net.Build.Core Changelog
+## v6.0.0
+### Breaking changes
+- The EscapedStringProvider class has been moved to War3Net.CodeAnalysis.Jass.
+### Changes
+- Added W3MathF class.
+### Bugfixes
+- Fixed exception when deserializing MapInfo.EditorVersion as JSON string.
+
## v1.5.3
### Changes
- Add UseNewFormat property to MapCustomTextTriggers.
diff --git a/docs/changelogs/War3Net.Build.changelog.md b/docs/changelogs/War3Net.Build.changelog.md
index 00a17935..017ed5dd 100644
--- a/docs/changelogs/War3Net.Build.changelog.md
+++ b/docs/changelogs/War3Net.Build.changelog.md
@@ -1,5 +1,11 @@
# War3Net.Build Changelog
+## v6.0.0
+### Breaking changes
+- MapScriptBuilder methods have been renamed and now write to an IndentedTextWriter instead of returning a syntax class.
+- TriggerRenderer and TriggerRendererContext now expect an IndentedTextWriter instead of JassRenderer/TextWriter.
+- MapScriptBuilder's C# api methods have been removed, you can now use the GenerateGlobals methods and manually transpile to C#.
+
## v1.5.0
### Changes
- Support parsing and serializing .wtg files.
diff --git a/docs/changelogs/War3Net.CodeAnalysis.Jass.changelog.md b/docs/changelogs/War3Net.CodeAnalysis.Jass.changelog.md
new file mode 100644
index 00000000..cc5b44cd
--- /dev/null
+++ b/docs/changelogs/War3Net.CodeAnalysis.Jass.changelog.md
@@ -0,0 +1,5 @@
+# War3Net.CodeAnalysis.Jass Changelog
+
+## v6.0.0
+### Breaking changes
+- Breaking changes have been documented in [the migration guide](../guides/jass-migration-guide-v5-to-v6.md)
diff --git a/docs/guides/jass-migration-guide-v5-to-v6.md b/docs/guides/jass-migration-guide-v5-to-v6.md
new file mode 100644
index 00000000..aa854aa5
--- /dev/null
+++ b/docs/guides/jass-migration-guide-v5-to-v6.md
@@ -0,0 +1,231 @@
+# War3Net.CodeAnalysis.Jass v5 -> v6 migration guide
+
+## Overview
+
+War3Net.CodeAnalysis.Jass v6.0.0 introduced major breaking changes to make the library better suited for certain use cases.
+
+New classes have been added for tokens and trivia, making it possible to model a JASS script with 100% accuracy.
+
+This guide contains mapping tables for migrating your code from v5 to v6.
+
+## Syntax changes
+
+New types
+
+New syntax node classes to hold tokens:
+
+| Class name | Token(s) |
+|---------------------------------------|-----------------------|
+| `JassElementAccessClauseSyntax` | `[` and `]` |
+| `JassElseIfClauseDeclaratorSyntax` | `elseif` and `then` |
+| `JassEmptyParameterListSyntax` | `takes` and `nothing` |
+| `JassGlobalConstantDeclarationSyntax` | `constant` |
+| `JassIfClauseDeclaratorSyntax` | `if` and `then` |
+| `JassReturnClauseSyntax` | `returns` |
+
+Other new syntax node classes:
+
+| Class name | Purpose |
+|-----------------------------------------------|--------------------------------------------------------------------------------------------|
+| `JassIfClauseSyntax` | Holds `JassIfClauseDeclaratorSyntax` and statements |
+| `JassParameterListOrEmptyParameterListSyntax` | Abstract base class for empty (`takes nothing`) and not-empty (`takes `) lists |
+| `JassSyntaxNode` | Abstract base class for all new and existing syntax node classes |
+
+Other new types:
+
+| Type name | Purpose |
+|-------------------------|--------------------------------------------------------------------------------|
+| `JassSyntaxKind` | Mainly used to tell the difference between literals and operators |
+| `JassSyntaxNodeOrToken` | Can be used to model "custom script actions" (one full line of the map script) |
+| `JassSyntaxToken` | Holds a token's text and trivia |
+| `JassSyntaxTrivia` | Contains trivia as text (whitespace, newlines, single line comments) |
+| `JassSyntaxTriviaList` | A collection of leading or trailing trivia for a token |
+
+
+
+Renamed types
+
+The following interfaces have been changed to abstract classes:
+
+| Old type name | New type name |
+|------------------------------|---------------------------------------|
+| `IExpressionSyntax` | `JassExpressionSyntax` |
+| `IGlobalDeclarationSyntax` | `JassGlobalDeclarationSyntax` |
+| `IStatementSyntax` | `JassStatementSyntax` |
+| `ITopLevelDeclarationSyntax` | `JassTopLevelDeclarationSyntax` |
+| `IVariableDeclaratorSyntax` | `JassVariableOrArrayDeclaratorSyntax` |
+
+The following classes have been renamed:
+
+| Old class name | New class name |
+|--------------------------------------|---------------------------------------|
+| `JassArrayReferenceExpressionSyntax` | `JassElementAccessExpressionSyntax` |
+| `JassGlobalDeclarationListSyntax` | `JassGlobalsDeclarationSyntax` |
+| `JassGlobalDeclarationSyntax` | `JassGlobalVariableDeclarationSyntax` |
+
+
+
+Replaced types
+
+Specific literal expression classes have been removed, you can now use the generic JassLiteralExpressionSyntax class.
+
+The new JassLiteralExpressionSyntax contains a token (with string text) property instead of the actual type of the expression.
+
+| Old type | New JassSyntaxKind |
+|------------------------------------------|-----------------------------------------------|
+| `JassBooleanLiteralExpressionSyntax` | `JassSyntaxKind.BooleanLiteralExpression` |
+| `JassCharacterLiteralExpressionSyntax` | `JassSyntaxKind.CharacterLiteralExpression` |
+| `JassDecimalLiteralExpressionSyntax` | `JassSyntaxKind.DecimalLiteralExpression` |
+| `JassFourCCLiteralExpressionSyntax` | `JassSyntaxKind.FourCCLiteralExpression` |
+| `JassHexadecimalLiteralExpressionSyntax` | `JassSyntaxKind.HexadecimalLiteralExpression` |
+| `JassNullLiteralExpressionSyntax` | `JassSyntaxKind.NullLiteralExpression` |
+| `JassOctalLiteralExpressionSyntax` | `JassSyntaxKind.OctalLiteralExpression` |
+| `JassRealLiteralExpressionSyntax` | `JassSyntaxKind.RealLiteralExpression` |
+| `JassStringLiteralExpressionSyntax` | `JassSyntaxKind.StringLiteralExpression` |
+
+Script line interfaces have been removed, the new `JassSyntaxNodeOrToken` serves the same purpose:
+
+| Removed interface |
+|--------------------------|
+| `IDeclarationLineSyntax` |
+| `IGlobalLineSyntax` |
+| `IStatementLineSyntax` |
+
+Custom script action classes have been removed, these have been replaced by new syntax node classes or the `JassSyntaxToken` class:
+
+| Removed class | Replacement class or token kind |
+|-------------------------------------|-------------------------------------|
+| `JassDebugCustomScriptAction` | NO REPLACEMENT YET |
+| `JassElseCustomScriptAction` | `JassSyntaxKind.ElseKeyword` |
+| `JassElseIfCustomScriptAction` | `JassElseIfClauseDeclaratorSyntax` |
+| `JassEndFunctionCustomScriptAction` | `JassSyntaxKind.EndFunctionKeyword` |
+| `JassEndGlobalsCustomScriptAction` | `JassSyntaxKind.EndGlobalsKeyword` |
+| `JassEndIfCustomScriptAction` | `JassSyntaxKind.EndIfKeyword` |
+| `JassEndLoopCustomScriptAction` | `JassSyntaxKind.EndLoopKeyword` |
+| `JassFunctionCustomScriptAction` | `JassFunctionDeclaratorSyntax` |
+| `JassGlobalsCustomScriptAction` | `JassSyntaxKind.GlobalsKeyword` |
+| `JassIfCustomScriptAction` | `JassIfClauseDeclaratorSyntax` |
+| `JassLoopCustomScriptAction` | `JassSyntaxKind.LoopKeyword` |
+
+The `BinaryOperatorType` and `UnaryOperatorType` enums have been removed, the type of the operator can now be determined by the syntax kind of the operator token:
+
+| Old member name | New token kind |
+|-------------------------------------|-----------------------------------------|
+| `BinaryOperatorType.Add` | `JassSyntaxKind.PlusToken` |
+| `BinaryOperatorType.Subtract` | `JassSyntaxKind.MinusToken` |
+| `BinaryOperatorType.Multiplication` | `JassSyntaxKind.AsteriskToken` |
+| `BinaryOperatorType.Division` | `JassSyntaxKind.SlashToken` |
+| `BinaryOperatorType.GreaterThan` | `JassSyntaxKind.GreaterThanToken` |
+| `BinaryOperatorType.LessThan` | `JassSyntaxKind.LessThanToken` |
+| `BinaryOperatorType.Equals` | `JassSyntaxKind.EqualsEqualsToken` |
+| `BinaryOperatorType.NotEquals` | `JassSyntaxKind.ExclamationEqualsToken` |
+| `BinaryOperatorType.GreaterOrEqual` | `JassSyntaxKind.GreaterThanEqualsToken` |
+| `BinaryOperatorType.LessOrEqual` | `JassSyntaxKind.LessThanEqualsToken` |
+| `BinaryOperatorType.And` | `JassSyntaxKind.AndKeyword` |
+| `BinaryOperatorType.Or` | `JassSyntaxKind.OrKeyword` |
+| `UnaryOperatorType.Plus` | `JassSyntaxKind.PlusToken` |
+| `UnaryOperatorType.Minus` | `JassSyntaxKind.MinusToken` |
+| `UnaryOperatorType.Not` | `JassSyntaxKind.NotKeyword` |
+
+Comments and empty lines are now handled by trivia:
+
+| Removed class |
+| --------------------|
+| `JassCommentSyntax` |
+| `JassEmptySyntax` |
+
+
+
+Removed types
+
+The following types have been removed:
+
+| Removed type | Alternative |
+|-------------------------------|---------------------------------------------------------------------|
+| `IInvocationSyntax` | NO ALTERNATIVE |
+| `IVariableDeclaratorSyntax` | Use `GetVariableType()` and `GetIdentifierName()` extension methods |
+| `JassDebugCustomScriptAction` | NO ALTERNATIVE |
+
+The following types are no longer relevant:
+
+| Removed type | Alternative |
+|-----------------------------------------|----------------------------------------------------|
+| `JassStatementListSyntax` | Use `ImmutableArray` directly |
+| `JassVariableReferenceExpressionSyntax` | Use `JassIdentifierNameSyntax` directly |
+
+The following classes were unused and are no longer relevant:
+
+| Removed class |
+|----------------------------------|
+| `IMemberDeclarationSyntax` |
+| `IScopedDeclarationSyntax` |
+| `IScopedGlobalDeclarationSyntax` |
+
+
+
+Renamed members
+
+The following methods have been renamed in syntax node classes:
+
+| Old method name | New method name |
+|-----------------|------------------|
+| `Equals` | `IsEquivalentTo` |
+
+The following properties have been renamed.
+
+If the containing type has been changed or renamed, the new type name is also listed in the new column.
+
+| Old property name | New property name |
+|----------------------------------------------|---------------------------------------------------------|
+| `JassArgumentListSyntax.Arguments` | `ArgumentList` |
+| `JassArrayReferenceExpressionSyntax.Indexer` | `JassElementAccessExpressionSyntax.ElementAccessClause` |
+| `JassCallStatementSyntax.Arguments` | `ArgumentList` |
+| `JassGlobalDeclarationListSyntax.Globals` | `JassGlobalsDeclarationSyntax.GlobalDeclarations` |
+| `JassInvocationExpressionSyntax.Arguments` | `ArgumentList` |
+| `JassParameterListSyntax.Empty` | `JassEmptyParameterListSyntax.Value` |
+| `JassParameterListSyntax.Parameters` | `ParameterList` |
+| `JassTypeSyntax.Boolean` | `JassPredefinedTypeSyntax.Boolean` |
+| `JassTypeSyntax.Code` | `JassPredefinedTypeSyntax.Code` |
+| `JassTypeSyntax.Handle` | `JassPredefinedTypeSyntax.Handle` |
+| `JassTypeSyntax.Integer` | `JassPredefinedTypeSyntax.Integer` |
+| `JassTypeSyntax.Nothing` | `JassPredefinedTypeSyntax.Nothing` |
+| `JassTypeSyntax.Real` | `JassPredefinedTypeSyntax.Real` |
+| `JassTypeSyntax.String` | `JassPredefinedTypeSyntax.String` |
+
+
+
+Replaced members
+
+The following properties have been replaced:
+
+| Old property name | New property type and name | Old type |
+|---------------------------------------|-----------------------------------------------------|---------------------------|
+| `JassBinaryExpressionSyntax.Operator` | `JassSyntaxToken OperatorToken` | `BinaryOperatorType` |
+| `JassElseClauseSyntax.Body` | `ImmutableArray Statements` | `JassStatementListSyntax` |
+| `JassIdentifierNameSyntax.Name` | `JassSyntaxToken Token` | `string` |
+| `JassSetStatementSyntax.Indexer` | `JassElementAccessClauseSyntax ElementAccessClause` | `IExpressionSyntax` |
+| `JassUnaryExpressionSyntax.Operator` | `JassSyntaxToken OperatorToken` | `UnaryOperatorType` |
+
+Other replacements:
+
+| Old property name | Alternative |
+|----------------------------------------------------------|------------------------------------------------------|
+| `JassBooleanLiteralExpressionSyntax.False` | `JassSyntaxFactory.Literal(false)` |
+| `JassBooleanLiteralExpressionSyntax.True` | `JassSyntaxFactory.Literal(true)` |
+| `JassNativeFunctionDeclarationSyntax.FunctionDeclarator` | All declarator properties are now available directly |
+| `JassNullLiteralExpressionSyntax.Value` | `JassSyntaxFactory.Literal(null)` |
+| `JassTypeSyntax.TypeName` | `JassTypeSyntaxExtensions.GetToken()` |
+
+
+
+Other (breaking) changes
+
+- JassTypeSyntax is now abstract and inherits JassExpressionSyntax
+- JassIdentifierNameSyntax now inherits JassTypeSyntax -> JassExpressionSyntax
+- Properties that used to be of type `JassParameterListSyntax` are now `JassParameterListOrEmptyParameterListSyntax`
+- The constructor of syntax node classes is now internal
+- Properties have been changed from `{ get; init; }` to `{ get; }`
+- `JassSymbol` now contains both `char` and `string` constants, existing `char` constants got the `Char` suffix
+- `JassSyntaxFacts.IsWhitespaceCharacter(char)` now only considers spaces and tabs to be whitespace (previously used `char.IsWhitespace` and excluded \r and \n)
+
+
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index ccc2aceb..30bfe7ae 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -17,7 +17,7 @@
-
+
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
index 19ee7535..2311b170 100644
--- a/src/Directory.Build.targets
+++ b/src/Directory.Build.targets
@@ -14,4 +14,13 @@
$(PackageVersion)
+
+
+
+
+
+
+ %(ThisProjectPackageVersion.Version)
+
+
\ No newline at end of file
diff --git a/src/War3Net.Build.Core/Common/W3MathF.cs b/src/War3Net.Build.Core/Common/W3MathF.cs
new file mode 100644
index 00000000..f43586ca
--- /dev/null
+++ b/src/War3Net.Build.Core/Common/W3MathF.cs
@@ -0,0 +1,15 @@
+// ------------------------------------------------------------------------------
+//
+// Licensed under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// ------------------------------------------------------------------------------
+
+namespace War3Net.Build.Common
+{
+ public static class W3MathF
+ {
+ public const float Deg2Rad = 3.141593f / 180f;
+ public const float Rad2Deg = 180f / 3.141593f;
+ }
+}
\ No newline at end of file
diff --git a/src/War3Net.Build.Core/Serialization/Json/Info/MapInfo.cs b/src/War3Net.Build.Core/Serialization/Json/Info/MapInfo.cs
index f275779a..6cc88f53 100644
--- a/src/War3Net.Build.Core/Serialization/Json/Info/MapInfo.cs
+++ b/src/War3Net.Build.Core/Serialization/Json/Info/MapInfo.cs
@@ -34,7 +34,7 @@ internal void GetFrom(JsonElement jsonElement)
if (FormatVersion >= MapInfoFormatVersion.v18)
{
MapVersion = jsonElement.GetInt32(nameof(MapVersion));
- EditorVersion = (EditorVersion)jsonElement.GetInt32(nameof(EditorVersion));
+ EditorVersion = jsonElement.GetInt32Raw(nameof(EditorVersion));
if (FormatVersion >= MapInfoFormatVersion.v27)
{
diff --git a/src/War3Net.Build/CompileResult.cs b/src/War3Net.Build/CompileResult.cs
index dd90e358..6aa562b1 100644
--- a/src/War3Net.Build/CompileResult.cs
+++ b/src/War3Net.Build/CompileResult.cs
@@ -24,7 +24,7 @@ internal CompileResult(EmitResult emitResult)
_diagnostics = emitResult.Diagnostics;
}
- internal CompileResult(bool success, IEnumerable diagnostics)
+ internal CompileResult(bool success, IEnumerable? diagnostics)
{
_success = success;
_diagnostics = diagnostics?.ToImmutableArray() ?? ImmutableArray.Empty;
diff --git a/src/War3Net.Build/Extensions/MapExtensions.cs b/src/War3Net.Build/Extensions/MapExtensions.cs
index 890c5fe8..ba531618 100644
--- a/src/War3Net.Build/Extensions/MapExtensions.cs
+++ b/src/War3Net.Build/Extensions/MapExtensions.cs
@@ -53,17 +53,7 @@ public static void CompileScript(this Map map, MapScriptBuilder mapScriptBuilder
throw new ArgumentException($"The map's script language must be set to jass in order to use the jass compiler.", nameof(map));
}
- var compilationUnit = mapScriptBuilder.Build(map);
-
- using var stream = new MemoryStream();
- using (var writer = new StreamWriter(stream, _defaultEncoding, leaveOpen: true))
- {
- var renderer = new JassRenderer(writer);
- renderer.Render(compilationUnit);
- }
-
- stream.Position = 0;
- map.SetScriptFile(stream);
+ map.Script = mapScriptBuilder.Build(map);
}
public static CompileResult CompileScript(this Map map, Compiler compiler, IEnumerable luaSystemLibs)
@@ -133,7 +123,9 @@ public static CompileResult CompileScript(this Map map, Compiler compiler, MapSc
transpiler.RegisterJassFile(JassSyntaxFactory.ParseCompilationUnit(File.ReadAllText(commonJPath)));
transpiler.RegisterJassFile(JassSyntaxFactory.ParseCompilationUnit(File.ReadAllText(blizzardJPath)));
- var luaCompilationUnit = transpiler.Transpile(mapScriptBuilder.Build(map));
+ var mapScript = mapScriptBuilder.Build(map);
+ var jassCompilationUnit = JassSyntaxFactory.ParseCompilationUnit(mapScript);
+ var luaCompilationUnit = transpiler.Transpile(jassCompilationUnit);
using (var writer = new StreamWriter(stream, _defaultEncoding, leaveOpen: true))
{
var luaRenderOptions = new LuaSyntaxGenerator.SettingInfo
diff --git a/src/War3Net.Build/Extensions/ModifiedAbilityDataExtensions.cs b/src/War3Net.Build/Extensions/ModifiedAbilityDataExtensions.cs
index d4079fec..f7bcbe10 100644
--- a/src/War3Net.Build/Extensions/ModifiedAbilityDataExtensions.cs
+++ b/src/War3Net.Build/Extensions/ModifiedAbilityDataExtensions.cs
@@ -16,13 +16,32 @@ namespace War3Net.Build.Extensions
{
public static class ModifiedAbilityDataExtensions
{
+ private static readonly Lazy> _abilityOrderOnStrings = new(GetAbilityOrderOnStrings);
private static readonly Lazy> _abilityOrderOffStrings = new(GetAbilityOrderOffStrings);
+ public static bool TryGetOrderOnString(this ModifiedAbilityData abilityData, [NotNullWhen(true)] out string? orderOnString)
+ {
+ return _abilityOrderOnStrings.Value.TryGetValue(abilityData.AbilityId, out orderOnString);
+ }
+
public static bool TryGetOrderOffString(this ModifiedAbilityData abilityData, [NotNullWhen(true)] out string? orderOffString)
{
return _abilityOrderOffStrings.Value.TryGetValue(abilityData.AbilityId, out orderOffString);
}
+ private static Dictionary GetAbilityOrderOnStrings()
+ {
+ return new Dictionary
+ {
+ { "Ahea".FromRawcode(), "healon" },
+ { "ACsa".FromRawcode(), "flamingarrows" },
+ { "ANth".FromRawcode(), "Thornyshield" },
+ { "AEim".FromRawcode(), "immolation" },
+ { "ANba".FromRawcode(), "blackarrowon" },
+ { "AHds".FromRawcode(), "divineshield" },
+ };
+ }
+
private static Dictionary GetAbilityOrderOffStrings()
{
return new Dictionary
diff --git a/src/War3Net.Build/Extensions/TriggerDefinitionExtensions.cs b/src/War3Net.Build/Extensions/TriggerItemExtensions.cs
similarity index 75%
rename from src/War3Net.Build/Extensions/TriggerDefinitionExtensions.cs
rename to src/War3Net.Build/Extensions/TriggerItemExtensions.cs
index 2b2900a1..0c3f50d4 100644
--- a/src/War3Net.Build/Extensions/TriggerDefinitionExtensions.cs
+++ b/src/War3Net.Build/Extensions/TriggerItemExtensions.cs
@@ -1,5 +1,5 @@
-// ------------------------------------------------------------------------------
-//
+// ------------------------------------------------------------------------------
+//
// Licensed under the MIT license.
// See the LICENSE file in the project root for more information.
//
@@ -12,34 +12,34 @@
namespace War3Net.Build.Extensions
{
- public static class TriggerDefinitionExtensions
+ public static class TriggerItemExtensions
{
- public static string GetVariableName(this TriggerDefinition trigger)
+ public static string GetVariableName(this TriggerItem trigger)
{
return $"gg_trg_{trigger.GetTriggerIdentifierName()}";
}
- public static string GetInitTrigFunctionName(this TriggerDefinition trigger)
+ public static string GetInitTrigFunctionName(this TriggerItem trigger)
{
return $"InitTrig_{trigger.GetTriggerIdentifierName()}";
}
- public static string GetTrigConditionsFunctionName(this TriggerDefinition trigger)
+ public static string GetTrigConditionsFunctionName(this TriggerItem trigger)
{
return $"Trig_{trigger.GetTriggerIdentifierName()}_Conditions";
}
- public static string GetTrigActionsFunctionName(this TriggerDefinition trigger)
+ public static string GetTrigActionsFunctionName(this TriggerItem trigger)
{
return $"Trig_{trigger.GetTriggerIdentifierName()}_Actions";
}
- public static string GetTrigIdentifierBaseName(this TriggerDefinition trigger)
+ public static string GetTrigIdentifierBaseName(this TriggerItem trigger)
{
return $"Trig_{trigger.GetTriggerIdentifierName()}_";
}
- public static string GetTriggerIdentifierName(this TriggerDefinition trigger)
+ public static string GetTriggerIdentifierName(this TriggerItem trigger)
{
return Regex.Replace(trigger.Name, "[^A-Za-z0-9_]", match => new string('_', Encoding.UTF8.GetBytes(match.Value).Length));
}
diff --git a/src/War3Net.Build/Extensions/VariableDefinitionExtensions.cs b/src/War3Net.Build/Extensions/VariableDefinitionExtensions.cs
index 881e8a69..7e67ada0 100644
--- a/src/War3Net.Build/Extensions/VariableDefinitionExtensions.cs
+++ b/src/War3Net.Build/Extensions/VariableDefinitionExtensions.cs
@@ -19,7 +19,7 @@ public static string GetVariableName(this VariableDefinition variable)
return $"udg_{variable.Name}";
}
- public static IExpressionSyntax GetInitialValueExpression(this VariableDefinition variable)
+ public static JassExpressionSyntax GetInitialValueExpression(this VariableDefinition variable)
{
throw new NotImplementedException();
}
diff --git a/src/War3Net.Build/Extensions/WidgetDataExtensions.cs b/src/War3Net.Build/Extensions/WidgetDataExtensions.cs
index 356e9e91..1ab190ee 100644
--- a/src/War3Net.Build/Extensions/WidgetDataExtensions.cs
+++ b/src/War3Net.Build/Extensions/WidgetDataExtensions.cs
@@ -20,7 +20,7 @@ public static bool HasItemTable(this WidgetData widgetData)
public static bool HasItemTableSets(this WidgetData widgetData)
{
- return widgetData.ItemTableSets.Any(itemTableSet => itemTableSet.Items.Any());
+ return widgetData.ItemTableSets.Any(itemTableSet => itemTableSet.Items.Count > 0);
}
}
}
\ No newline at end of file
diff --git a/src/War3Net.Build/MapScriptBuilder.cs b/src/War3Net.Build/MapScriptBuilder.cs
index 7857c9a5..d33619a0 100644
--- a/src/War3Net.Build/MapScriptBuilder.cs
+++ b/src/War3Net.Build/MapScriptBuilder.cs
@@ -7,15 +7,15 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Reflection;
using War3Net.Build.Extensions;
using War3Net.Build.Info;
using War3Net.Build.Script;
-using War3Net.CodeAnalysis.Jass.Syntax;
-
-using SyntaxFactory = War3Net.CodeAnalysis.Jass.JassSyntaxFactory;
+using War3Net.CodeAnalysis;
+using War3Net.CodeAnalysis.Jass;
namespace War3Net.Build
{
@@ -97,224 +97,242 @@ public virtual void SetDefaultOptionsForMap(Map map)
UseWeatherEffectVariable = true;
}
- public virtual JassCompilationUnitSyntax Build(Map map)
+ public string Build(Map map)
{
if (map is null)
{
throw new ArgumentNullException(nameof(map));
}
- JassCommentSyntax commentLine1 = new("===========================================================================");
- JassCommentSyntax commentLine2 = new("***************************************************************************");
- JassCommentSyntax commentLine3 = new("*");
+ using var stringWriter = new StringWriter();
+ stringWriter.NewLine = JassSymbol.CarriageReturnLineFeed;
+ using var writer = new IndentedTextWriter(stringWriter);
+
+ Build(map, writer);
- List declarations = new();
+ return stringWriter.ToString();
+ }
+
+ public virtual void Build(Map map, IndentedTextWriter writer)
+ {
+ if (map is null)
+ {
+ throw new ArgumentNullException(nameof(map));
+ }
- void AppendBanner(string bannerText)
+ if (writer is null)
{
- declarations.Add(commentLine2);
- declarations.Add(commentLine3);
- declarations.Add(new JassCommentSyntax($"* {bannerText}"));
- declarations.Add(commentLine3);
- declarations.Add(commentLine2);
- declarations.Add(JassEmptySyntax.Value);
+ throw new ArgumentNullException(nameof(writer));
}
- void AppendBannerAndFunction(string bannerText, Func