Skip to content

Commit

Permalink
Register
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 3, 2024
1 parent 65b0b6a commit f765ebb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Jailbreak.English.Rebel;

public class Ic4Locale : IC4Locale, ILanguage<Formatting.Languages.English> {
public class C4Locale : IC4Locale, ILanguage<Formatting.Languages.English> {
public IView JihadC4Pickup
=> new SimpleView { RebelLocale.PREFIX, "You picked up a Jihad C4!" };

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

namespace Jailbreak.English.Warden;

public class WardenCmdOpenCommandNotifications : IWardenCmdOpenLocale,
public class WardenCmdOpenLocale : IWardenCmdOpenLocale,
ILanguage<Formatting.Languages.English> {
public IView CannotOpenYet(int seconds) {
return new SimpleView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Jailbreak.English.Warden;

public class WardenCmdRollCommandNotifications : IWardenCmdRollLocale,
public class WardenCmdRollLocale : IWardenCmdRollLocale,
ILanguage<Formatting.Languages.English> {
public IView Roll(int roll) {
return new SimpleView {
Expand Down
7 changes: 5 additions & 2 deletions mod/Jailbreak.Zones/SqlZoneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public class SqlZoneManager(IZoneFactory factory) : IZoneManager {

public void Start(BasePlugin basePlugin) {
plugin = basePlugin;
Server.NextFrameAsync(async () => { await createTable(); });

basePlugin.RegisterListener<Listeners.OnMapStart>(OnMapStart);
basePlugin.RegisterListener<Listeners.OnMapEnd>(OnMapEnd);
}

public void Dispose() {
plugin.RemoveListener<Listeners.OnMapStart>(OnMapStart);
plugin.RemoveListener<Listeners.OnMapEnd>(OnMapEnd);
}

public async Task DeleteZone(int zoneId, string map) {
Expand Down Expand Up @@ -164,7 +164,10 @@ PRIMARY KEY(map, zoneid, pointid))
}

private void OnMapStart(string mapname) {
Server.NextFrameAsync(async () => await LoadZones(mapname));
Server.NextFrameAsync(async () => {
await createTable();
await LoadZones(mapname);
});
}

private MySqlCommand queryAllZones(string map, ZoneType type) {
Expand Down
77 changes: 9 additions & 68 deletions public/Jailbreak.Formatting/Logistics/LanguageConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,20 @@ public LanguageConfig(IServiceCollection collection) {
this.collection = collection;
}

// public void WithGenericCommand<TGenericCommand>()
// where TGenericCommand : class, ILanguage<TDialect>,
// IGenericCmdLocale {
// collection.AddSingleton<IGenericCmdLocale, TGenericCommand>();
// }
//
// public void WithWarden<TWarden>()
// where TWarden : class, ILanguage<TDialect>, IWardenLocale {
// collection.AddSingleton<IWardenLocale, TWarden>();
// }
//
// public void WithRebel<TRebel>()
// where TRebel : class, ILanguage<TDialect>, IRebelLocale {
// collection.AddSingleton<IRebelLocale, TRebel>();
// }
//
// public void WithJihadC4<TJihadC4>()
// where TJihadC4 : class, ILanguage<TDialect>, IC4Locale {
// collection.AddSingleton<IC4Locale, TJihadC4>();
// }
//
// public void WithSpecialDay<TSpecialDay>()
// where TSpecialDay : class, ILanguage<TDialect>, ISDLocale {
// collection.AddSingleton<ISDLocale, TSpecialDay>();
// }
//
// public void WithLogging<TLogging>()
// where TLogging : class, ILanguage<TDialect>, ILogLocale {
// collection.AddSingleton<ILogLocale, TLogging>();
// }
//
// public void WithRollCommand<TRollCommand>()
// where TRollCommand : class, ILanguage<TDialect>, IWardenCmdRollLocale {
// collection.AddSingleton<IWardenCmdRollLocale, TRollCommand>();
// }
//
// public void WithLastRequest<TLastRequest>()
// where TLastRequest : class, ILanguage<TDialect>, ILRLocale {
// collection.AddSingleton<ILRLocale, TLastRequest>();
// }
//
// public void WithSpecialTreatment<TSpecialTreatment>()
// where TSpecialTreatment : class, ILanguage<TDialect>,
// IWardenSTLocale {
// collection
// .AddSingleton<IWardenSTLocale, TSpecialTreatment>();
// }
//
// public void WithMute<TMute>()
// where TMute : class, ILanguage<TDialect>, IWardenPeaceLocale {
// collection.AddSingleton<IWardenPeaceLocale, TMute>();
// }
//
// public void WithRaceLR<TRaceLR>()
// where TRaceLR : class, ILanguage<TDialect>, ILRRaceLocale {
// collection.AddSingleton<ILRRaceLocale, TRaceLR>();
// }
//
// public void WithLastGuard<TLastGuard>()
// where TLastGuard : class, ILanguage<TDialect>, ILGLocale {
// collection.AddSingleton<ILGLocale, TLastGuard>();
// }
//
// public void WithOpenCommand<TOpenCommand>()
// where TOpenCommand : class, ILanguage<TDialect>, IWardenCmdOpenLocale {
// collection.AddSingleton<IWardenCmdOpenLocale, TOpenCommand>();
// }

public void Configure(Dictionary<Type, Type> serviceMap) {
foreach (var (service, implementation) in serviceMap) {
var method = typeof(IServiceCollection).GetMethod("AddSingleton")
?.MakeGenericMethod(service, implementation);
method?.Invoke(collection, null);
}
}
}

public static class ServiceCollectionExtensions {
public static void AddLanguage<TDialect>(this IServiceCollection services,
Action<LanguageConfig<TDialect>> configure)
where TDialect : class, IDialect {
var config = new LanguageConfig<TDialect>(services);
configure(config);
}
}
28 changes: 20 additions & 8 deletions src/Jailbreak/JailbreakServiceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ public void ConfigureServices(IServiceCollection serviceCollection) {
serviceCollection.AddJailbreakSpecialDay();
serviceCollection.AddJailbreakZones();

serviceCollection.AddSingleton<ILogLocale, LogLocale>();
serviceCollection.AddSingleton<IRebelLocale, RebelLocale>();
serviceCollection.AddSingleton<IGenericCmdLocale, GenericCmdLocale>();
serviceCollection.AddSingleton<ILRLocale, LastRequestLocale>();
serviceCollection.AddSingleton<ILRCFLocale, CoinflipLocale>();
serviceCollection.AddSingleton<ILRRPSLocale, RPSLocale>();
serviceCollection.AddSingleton<ILRRaceLocale, RaceLocale>();
serviceCollection.AddSingleton<ILGLocale, IlgLocale>();
serviceCollection.AddSingleton<ISDLocale, IsdLocale>();
serviceCollection.AddSingleton<IWardenLocale, WardenLocale>();
serviceCollection.AddSingleton<IWardenSTLocale, IstLocale>();
serviceCollection.AddSingleton<IWardenCmdOpenLocale, WardenCmdOpenLocale>();
serviceCollection.AddSingleton<IWardenCmdRollLocale, WardenCmdRollLocale>();
serviceCollection.AddSingleton<IWardenPeaceLocale, WardenPeaceLocale>();
serviceCollection.AddSingleton<IC4Locale, C4Locale>();

// Add in english localization
serviceCollection.AddLanguage<Formatting.Languages.English>(config => {
var serviceMap = new Dictionary<Type, Type> {
{ typeof(IC4Locale), typeof(Ic4Locale) },
{ typeof(IC4Locale), typeof(C4Locale) },
{ typeof(IGenericCmdLocale), typeof(GenericCmdLocale) },
{ typeof(ILGLocale), typeof(IlgLocale) },
{ typeof(ILRCFLocale), typeof(CoinflipLocale) },
Expand All @@ -60,13 +76,9 @@ public void ConfigureServices(IServiceCollection serviceCollection) {
{ typeof(ILogLocale), typeof(LogLocale) },
{ typeof(IRebelLocale), typeof(RebelLocale) },
{ typeof(ISDLocale), typeof(IsdLocale) },
{ typeof(IWardenSTLocale), typeof(IstLocale) }, {
typeof(IWardenCmdOpenLocale),
typeof(WardenCmdOpenCommandNotifications)
}, {
typeof(IWardenCmdRollLocale),
typeof(WardenCmdRollCommandNotifications)
},
{ typeof(IWardenSTLocale), typeof(IstLocale) },
{ typeof(IWardenCmdOpenLocale), typeof(WardenCmdOpenLocale) },
{ typeof(IWardenCmdRollLocale), typeof(WardenCmdRollLocale) },
{ typeof(IWardenLocale), typeof(WardenLocale) },
{ typeof(IWardenPeaceLocale), typeof(WardenPeaceLocale) }
};
Expand Down

0 comments on commit f765ebb

Please sign in to comment.