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
11 changes: 11 additions & 0 deletions Stoker.Base/Builder/CommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ public ArgumentBuilder<T> WithArgument<T>(string name){
return new ArgumentBuilder<T>(this, argument);
}

public ArgumentBuilder<string> WithSimpleNameArg()
{
var argument = new Argument<string>
{
Name = "name"
};
_command.AddArgument(argument);
_command.simpleNameArg = true;
return new ArgumentBuilder<string>(this, argument);
}

/// <summary>
/// Adds an option to the command.
/// </summary>
Expand Down
70 changes: 56 additions & 14 deletions Stoker.Base/Commands/CardCommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using ShinyShoe.Loading;
using Stoker.Base.Builder;
using Stoker.Base.Extension;
using Stoker.Base.Impl;
using Stoker.Base.Interfaces;
using TrainworksReloaded.Base;
using System.Reflection;
using TrainworksReloaded.Core;
using TrainworksReloaded.Core.Enum;
using TrainworksReloaded.Core.Interfaces;
Expand All @@ -21,9 +20,23 @@ public static ICommand Create()
.WithDescription("Manage cards")
.WithSubCommand("add")
.WithDescription("Add a card to the deck")
.WithArgument<string>("name")
.WithSimpleNameArg()
.WithDescription("The name of the card to add")
.WithSuggestions(() => [.. Railend.GetContainer().GetInstance<IRegister<CardData>>().GetAllIdentifiers(RegisterIdentifierType.ReadableID).Select(c => c.ToString())])
.WithSuggestions(() =>
{
Type type = typeof(CheatManager);
FieldInfo field = type.GetField("allGameData", BindingFlags.NonPublic | BindingFlags.Static);

if (field != null)
{
AllGameData? allGameData = field.GetValue(null) as AllGameData;
if (allGameData != null)
{
return [.. allGameData.GetAllCardData().Select(s => s.Cheat_GetNameEnglish())];
}
}
return [];
})
.WithParser((xs) => xs)
.Parent()
.SetHandler((args) =>
Expand Down Expand Up @@ -90,9 +103,23 @@ public static ICommand Create()
.Parent()
.WithSubCommand("remove")
.WithDescription("Remove a card from the deck")
.WithArgument<string>("name")
.WithSimpleNameArg()
.WithDescription("The name of the card to remove")
.WithSuggestions(() => [.. Railend.GetContainer().GetInstance<IRegister<CardData>>().GetAllIdentifiers(RegisterIdentifierType.ReadableID).Select(c => c.ToString())])
.WithSuggestions(() =>
{
Type type = typeof(CheatManager);
FieldInfo field = type.GetField("saveManager", BindingFlags.NonPublic | BindingFlags.Static);

if (field != null)
{
SaveManager? saveManager = field.GetValue(null) as SaveManager;
if (saveManager != null)
{
return [.. saveManager.GetDeckState().Select(s => s.GetTitleKey().LocalizeEnglish(true, null))];
}
}
return [];
})
.WithParser((xs) => xs)
.Parent()
.SetHandler((args) =>
Expand Down Expand Up @@ -120,7 +147,7 @@ public static ICommand Create()
.Parent()
.WithOption<int>("page-size")
.WithDescription("The number of cards to list per page")
.WithDefaultValue("10")
.WithDefaultValue("50")
.WithAliases("ps")
.WithParser((xs) => int.Parse(xs))
.Parent()
Expand All @@ -135,15 +162,30 @@ public static ICommand Create()
throw new Exception("Invalid --page option");
if (options["page-size"] is not int pageSize)
throw new Exception("Invalid --page-size option");
var cards = Railend.GetContainer().GetInstance<IRegister<CardData>>().GetAllIdentifiers(RegisterIdentifierType.ReadableID);
var startIndex = (page - 1) * pageSize;
var endIndex = startIndex + pageSize;
var pageCards = cards.Skip(startIndex).Take(pageSize);
LoggerLazy.Value.Log("Cards:");
foreach (var card in pageCards)


Type type = typeof(CheatManager);
FieldInfo field = type.GetField("allGameData", BindingFlags.NonPublic | BindingFlags.Static);

if (field != null)
{
LoggerLazy.Value.Log($" {card}");
AllGameData? allGameData = field.GetValue(null) as AllGameData;
if (allGameData != null)
{
List<CardData> cards = allGameData.GetAllCardData().ToList();
cards.FindAll(c => c.IsUnitAbility()).ForEach(c => cards.Remove(c)); // Remove unit abilities
cards.Sort((x, y) => string.Compare(x.Cheat_GetNameEnglish(), y.Cheat_GetNameEnglish(), StringComparison.OrdinalIgnoreCase));
var startIndex = (page - 1) * pageSize;
var endIndex = startIndex + pageSize;
var pageCards = cards.Skip(startIndex).Take(pageSize);
LoggerLazy.Value.Log("Cards:");
foreach (var card in pageCards)
{
LoggerLazy.Value.Log($"{card.Cheat_GetNameEnglish()}");
}
}
}

return Task.CompletedTask;
})
.UseHelpMiddleware()
Expand Down
80 changes: 80 additions & 0 deletions Stoker.Base/Commands/EventCommandFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using HarmonyLib;
using Stoker.Base.Builder;
using Stoker.Base.Extension;
using Stoker.Base.Interfaces;
using System.Reflection;
using TrainworksReloaded.Core;

namespace Stoker.Base.Commands
{
public class EventCommandFactory
{
private static Lazy<ConsoleLogger> LoggerLazy { get; set; } = new(() => Railend.GetContainer().GetInstance<ConsoleLogger>());

public static ICommand Create()
{
var command = new CommandBuilder("event")
.WithDescription("Manage events")
.WithSubCommand("trigger")
.WithDescription("Trigger an event")
.WithSimpleNameArg()
.WithDescription("The name of the event to trigger")
.WithSuggestions(() =>
{
Type type = typeof(CheatManager);
FieldInfo field = type.GetField("allGameData", BindingFlags.NonPublic | BindingFlags.Static);

if (field != null)
{
AllGameData? allGameData = field.GetValue(null) as AllGameData;
if (allGameData != null)
{
return [.. allGameData.GetAllStoryEventData().Select(s => s.name)];
}
}
return [];
})
.WithParser((xs) => xs)
.Parent()
.SetHandler((args) =>
{
var arguments = args.Arguments;
if (!arguments.ContainsKey("name"))
throw new Exception("Missing <name> argument");
if (arguments["name"] is not string eventName)
throw new Exception("Invalid <name> argument");
if (string.IsNullOrEmpty(eventName))
throw new Exception("Empty <name> argument");
LoggerLazy.Value.Log($"Trigerring event: {eventName}");
AccessTools.Method(typeof(CheatManager), "Command_StartEvent").Invoke(null, [eventName]);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.WithSubCommand("list")
.WithDescription("List all events")
.SetHandler((args) =>
{
Type type = typeof(CheatManager);
FieldInfo field = type.GetField("allGameData", BindingFlags.NonPublic | BindingFlags.Static);

if (field != null)
{
AllGameData? allGameData = field.GetValue(null) as AllGameData;
if (allGameData != null)
{
List<String> names = [.. allGameData.GetAllStoryEventData().Select(s => s.name)];
names.Sort();
names.ForEach(s => LoggerLazy.Value.Log(s));
}
}
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.UseHelpMiddleware()
.Build();
return command;
}
}
}
86 changes: 86 additions & 0 deletions Stoker.Base/Commands/NodeCommandFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using HarmonyLib;
using Stoker.Base.Builder;
using Stoker.Base.Extension;
using Stoker.Base.Interfaces;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using TrainworksReloaded.Core;

namespace Stoker.Base.Commands
{
public class NodeCommandFactory
{
private static Lazy<ConsoleLogger> LoggerLazy { get; set; } = new(() => Railend.GetContainer().GetInstance<ConsoleLogger>());

public static ICommand Create()
{
var command = new CommandBuilder("node")
.WithDescription("Manage nodes")
.WithSubCommand("next")
.WithDescription("Move to the next node")
.SetHandler((args) =>
{
LoggerLazy.Value.Log($"Moving to next node");
AccessTools.Method(typeof(CheatManager), "Command_NextNode").Invoke(null, []);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.WithSubCommand("prev")
.WithDescription("Move to the previous node")
.SetHandler((args) =>
{
LoggerLazy.Value.Log($"Moving to previous node");
AccessTools.Method(typeof(CheatManager), "Command_PreviousNode").Invoke(null, []);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.WithSubCommand("final")
.WithDescription("Move to the final node")
.SetHandler((args) =>
{
LoggerLazy.Value.Log($"Moving to final node");
AccessTools.Method(typeof(CheatManager), "Command_FinalNode").Invoke(null, []);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.WithSubCommand("tfb")
.WithDescription("Move to tfb")
.SetHandler((args) =>
{
LoggerLazy.Value.Log($"Moving to tfb");
AccessTools.Method(typeof(CheatManager), "Command_JumpToTFB").Invoke(null, []);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.WithSubCommand("reset")
.WithDescription("Reset node")
.SetHandler((args) =>
{
LoggerLazy.Value.Log($"Resetting node");
AccessTools.Method(typeof(CheatManager), "Command_ResetNode").Invoke(null, []);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.WithSubCommand("side")
.WithDescription("Change to the other side of the node")
.SetHandler((args) =>
{
LoggerLazy.Value.Log($"Changing to the other side of the node");
AccessTools.Method(typeof(CheatManager), "Command_ChangeSides").Invoke(null, []);
return Task.CompletedTask;
})
.UseHelpMiddleware()
.Parent()
.UseHelpMiddleware()
.Build();
return command;
}
}
}
Loading