-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from KSP2Community/dev
0.11.0 - Add slotted mixins and an error counter
- Loading branch information
Showing
24 changed files
with
2,701 additions
and
2,178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/PatchManager.SassyPatching/Nodes/Statements/SelectionLevel/MixinBlockInclude.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using PatchManager.SassyPatching.Exceptions; | ||
using PatchManager.SassyPatching.Interfaces; | ||
using Environment = PatchManager.SassyPatching.Execution.Environment; | ||
|
||
namespace PatchManager.SassyPatching.Nodes.Statements.SelectionLevel; | ||
|
||
/// <summary> | ||
/// Represents a mixin block include (i.e. slotting actions into a mixin) | ||
/// </summary> | ||
public class MixinBlockInclude : Node, ISelectionAction | ||
{ | ||
/// <summary> | ||
/// The name of the mixin being included | ||
/// </summary> | ||
public readonly string MixinName; | ||
/// <summary> | ||
/// The list of arguments to the mixin being included | ||
/// </summary> | ||
public readonly List<CallArgument> Arguments; | ||
|
||
/// <summary> | ||
/// The actions to be slotted into the mixin | ||
/// </summary> | ||
public readonly List<Node> SlotActions; | ||
|
||
internal MixinBlockInclude(Coordinate c, string mixinName, List<CallArgument> arguments, List<Node> slotActions) : base(c) | ||
{ | ||
MixinName = mixinName; | ||
Arguments = arguments; | ||
SlotActions = slotActions; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void ExecuteIn(Environment environment) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void ExecuteOn(Environment environment, ISelectable selectable, IModifiable modifiable) | ||
{ | ||
if (environment.GlobalEnvironment.AllMixins.TryGetValue(MixinName, out var mixin)) | ||
{ | ||
try | ||
{ | ||
var subEnv = new Environment(environment.GlobalEnvironment, environment) | ||
{ | ||
SlotActions = SlotActions | ||
}; | ||
mixin.Include(subEnv,Arguments.Select(x => x.Compute(environment)).ToList(),selectable,modifiable); | ||
} | ||
catch (InvocationException e) | ||
{ | ||
throw new InterpreterException(Coordinate, e.ToString()); | ||
} | ||
} | ||
else | ||
{ | ||
throw new InterpreterException(Coordinate, $"{MixinName} is not a valid mixin"); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/PatchManager.SassyPatching/Nodes/Statements/SelectionLevel/MixinSlot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using PatchManager.SassyPatching.Exceptions; | ||
using PatchManager.SassyPatching.Interfaces; | ||
using Environment = PatchManager.SassyPatching.Execution.Environment; | ||
|
||
namespace PatchManager.SassyPatching.Nodes.Statements.SelectionLevel; | ||
|
||
public class MixinSlot(Coordinate c) : Node(c), ISelectionAction | ||
{ | ||
public override void ExecuteIn(Environment environment) | ||
{ | ||
} | ||
|
||
public void ExecuteOn(Environment environment, ISelectable selectable, IModifiable modifiable) | ||
{ | ||
var actions = environment.SlotActions; | ||
if (actions == null) | ||
{ | ||
throw new InterpreterException(Coordinate, "Attempting to insert into a mixin slot without there being any actions passed for this purpose"); | ||
} | ||
|
||
foreach (var action in actions) | ||
{ | ||
if (action is ISelectionAction selectionAction) | ||
{ | ||
selectionAction.ExecuteOn(environment, selectable, modifiable); | ||
} | ||
else | ||
{ | ||
action.ExecuteIn(environment); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.