Skip to content

itsAudioo/SwDevtools

Repository files navigation

SwDevtools

Helper utilities for building SwiftlyS2 CS2 plugins

SwDevtools provides opinionated building blocks for Counter-Strike 2 plugins built on SwiftlyS2.

It focuses on:

  • Simple helper classes and services
  • Helping speed up development flow by reducing boilerplate code

Installation

Add the package to your plugin project:

dotnet add package SwDevtools

Your project should already reference SwiftlyS2.CS2.

Basic Usage

Inside your BasePlugin class, create a scoped service provider when the plugin loads and register SwDevtools services via AddSwDevtoolsKit:

using SwDevtools;
using SwiftlyS2.Shared;
using SwiftlyS2.Shared.Plugins;

public sealed class Plugin(ISwiftlyCore core) : BasePlugin(core)
{
    public override void Load(bool hotReload)
    {
        ServiceCollection services = new();
        services
            .AddSwiftly(this.Core)
            .AddSwDevtoolsKit(this.Core, this)
            .AddSingleton<TestService>();

        var provider = services.BuildServiceProvider();

        provider.GetRequiredService<TestService>().Run();
    }
}

AddSwDevtoolsKit wires up (for now):

  • ISwiftlyCore – the Swiftly core instance
  • IPluginLogger – plugin-scoped logger
  • IJsonConfig – JSON configuration helper
  • ITomlConfig – TOML configuration helper
  • ITranslate – player-localized translation helper

More services will be added in the future.

Consuming Services

Prefer constructor injection for your services:

using SwDevtools.Logging;

public sealed class TestService(IPluginLogger logger)
{
    public void Run() =>
        logger.Info("TestService running");
}

Property injection is optional and only applies to properties explicitly annotated with [Inject].

using SwDevtools;
using SwDevtools.Injection;
using SwDevtools.Logging;

public sealed class Plugin(ISwiftlyCore core) : BasePlugin(core)
{
    [Inject] public IPluginLogger Logger { get; set; } = null!;

    public override void Load(bool hotReload)
    {
        ServiceCollection services = new();
        services
            .AddSwiftly(this.Core)
            .AddSwDevtoolsKit(this.Core, this);

        var provider = services.BuildServiceProvider();
        provider.InjectProperties(this);

        this.Logger.Info("Plugin loaded");
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages