Skip to content

Commit

Permalink
Renamed actions
Browse files Browse the repository at this point in the history
  • Loading branch information
krafs committed Mar 17, 2024
1 parent 6ed1a4f commit b52ba86
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 142 deletions.
8 changes: 4 additions & 4 deletions Defs/Actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
<defName>LevelUpActionDef_Sound</defName>
<label>Sound</label>
<description>Plays a sound.</description>
<actionClass>LevelUp.SoundAction</actionClass>
<actionClass>LevelUp.LevelingAction_Sound</actionClass>
</LevelUp.ActionDef>

<LevelUp.ActionDef>
<defName>LevelUpActionDef_Animation</defName>
<label>Animation</label>
<description>Displays a simple, possibly animated, graphic on the colonist.</description>
<actionClass>LevelUp.AnimationAction</actionClass>
<actionClass>LevelUp.LevelingAction_Animation</actionClass>
</LevelUp.ActionDef>

<LevelUp.ActionDef>
<defName>LevelUpActionDef_Message</defName>
<label>Text message</label>
<description>Displays a text message in the top-left corner of the screen.</description>
<actionClass>LevelUp.MessageAction</actionClass>
<actionClass>LevelUp.LevelingAction_Message</actionClass>
</LevelUp.ActionDef>

<LevelUp.ActionDef>
<defName>LevelUpActionDef_OverheadMessage</defName>
<label>Overhead message</label>
<description>Displays a text message on the colonist.</description>
<actionClass>LevelUp.OverheadMessageAction</actionClass>
<actionClass>LevelUp.LevelingAction_OverheadMessage</actionClass>
</LevelUp.ActionDef>

</Defs>
2 changes: 1 addition & 1 deletion LevelUp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Lib.Harmony" Version="2.3.1.1" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="CopyModItemsToModOutput" AfterTargets="Build">
<Target Name="CopyToModOutput" AfterTargets="Build">
<Copy SourceFiles="@(ModItem)" DestinationFiles="$(LevelUpFolder)%(Identity)" />
</Target>

Expand Down
25 changes: 5 additions & 20 deletions Source/ActionMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ public sealed class ActionMaker : IExposable
{
internal List<LevelingAction> actions = [];
private Vector2 scrollPosition;
private readonly List<LevelingAction> preparedActions = [];

internal void Prepare()
{
preparedActions.Clear();

foreach (LevelingAction action in actions)
{
if (!action.active)
{
continue;
}

preparedActions.Add(action);

action.Prepare();
}
}

internal void ExecuteActions(LevelingInfo levelingInfo)
{
Expand All @@ -36,9 +18,12 @@ internal void ExecuteActions(LevelingInfo levelingInfo)
return;
}

for (int i = 0; i < preparedActions.Count; i++)
foreach (LevelingAction action in actions)
{
preparedActions[i].Execute(levelingInfo);
if (action.active)
{
action.Execute(levelingInfo);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Source/DefOfs.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using RimWorld;
using RimWorld;
using Verse;

namespace LevelUp;

#pragma warning disable IDE1006 // Naming Styles
[DefOf]
internal static class DefOfs
{
Expand Down
7 changes: 6 additions & 1 deletion Source/LevelUpMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ public LevelUpMod(ModContentPack content) : base(content)
{
Harmony harmony = new(content.PackageId);
Patcher.ApplyPatches(harmony);
LongEventHandler.ExecuteWhenFinished(() => LoadedModManager.GetMod<LevelUpMod>().GetSettings<Settings>());
LongEventHandler.ExecuteWhenFinished(static () =>
{
// Retrieve settings to initialize values, so they're in place.
// We do this in LongEvent because defs aren't loaded in Mod constructor.
LoadedModManager.GetMod<LevelUpMod>().GetSettings<Settings>();
});
}

public override string SettingsCategory()
Expand Down
3 changes: 0 additions & 3 deletions Source/Actions/LevelingAction.cs → Source/LevelingAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ public abstract class LevelingAction : IExposable
internal ActionDef actionDef = null!;
internal bool active;

internal virtual void Prepare()
{ }

internal abstract void Execute(LevelingInfo levelingInfo);

internal abstract void Draw(Rect rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace LevelUp;

public sealed class AnimationAction : LevelingAction
public sealed class LevelingAction_Animation : LevelingAction
{
private FleckDef fleckDef;
private FleckDef fleckDef = null!;
private Graphic_Single graphic = null!;
private Texture2D texture = null!;
private FleckDefExtension defExtension = null!;
Expand All @@ -19,14 +19,15 @@ internal FleckDef FleckDef
set
{
fleckDef = value;
Prepare();
defExtension = fleckDef.GetModExtension<FleckDefExtension>();
graphic = (Graphic_Single)fleckDef.graphicData.Graphic;
texture = ContentFinder<Texture2D>.Get(fleckDef.graphicData.texPath);
}
}

public AnimationAction()
public LevelingAction_Animation()
{
fleckDef = DefOfs.Radiance;
Prepare();
FleckDef = DefOfs.Radiance;
}

internal override void Execute(LevelingInfo levelingInfo)
Expand Down Expand Up @@ -55,13 +56,6 @@ internal override void Execute(LevelingInfo levelingInfo)
map.flecks.CreateFleck(fleckData);
}

internal override void Prepare()
{
defExtension = fleckDef.GetModExtension<FleckDefExtension>();
graphic = (Graphic_Single)fleckDef.graphicData.Graphic;
texture = ContentFinder<Texture2D>.Get(fleckDef.graphicData.texPath);
}

internal override void Draw(Rect rect)
{
Rect rowRect = new(rect) { height = 24f };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LevelUp;

public sealed class MessageAction : TextAction
public sealed class LevelingAction_Message : LevelingAction_Text
{
private bool historical;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LevelUp;

public sealed class OverheadMessageAction : TextAction
public sealed class LevelingAction_OverheadMessage : LevelingAction_Text
{
private bool historical;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LevelUp;

public sealed class SoundAction : LevelingAction
public sealed class LevelingAction_Sound : LevelingAction
{
private const float MinVolume = 0f;
private const float MaxVolume = 1.5f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LevelUp;

public abstract class TextAction : LevelingAction
public abstract class LevelingAction_Text : LevelingAction
{
private static readonly StringBuilder stringBuilder = new();
internal string text = string.Empty;
Expand Down
6 changes: 0 additions & 6 deletions Source/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ public sealed class Profile : IExposable
internal ActionMaker levelDownActionMaker = new();
private LevelingAction? selected;

internal void Prepare()
{
levelUpActionMaker.Prepare();
levelDownActionMaker.Prepare();
}

internal void Draw(Rect rect)
{
Rect leftRect = new(rect) { width = rect.width / 3 };
Expand Down
79 changes: 0 additions & 79 deletions Source/ProfileInitializer.cs

This file was deleted.

Loading

0 comments on commit b52ba86

Please sign in to comment.