From 52c6b02c6c4ef334f3b9dab1ebc9fe7aeaba0d58 Mon Sep 17 00:00:00 2001 From: dsdsfadas Date: Fri, 24 Jul 2026 13:09:41 +0300 Subject: [PATCH] Small code cleanup --- src/main/kotlin/buj/tl/IL.kt | 6 + src/main/kotlin/buj/tl/ILVoidDone.kt | 5 + src/main/kotlin/buj/tl/IScript.kt | 6 + .../buj/tl/ITranslationLocaleRegistry.kt | 6 + .../buj/tl/ITranslationLocaleResolver.kt | 5 + .../buj/tl/ITranslationParserFactory.kt | 3 + .../buj/tl/ITranslationParserProvider.kt | 3 + .../buj/tl/ITranslationParserSelector.kt | 3 + src/main/kotlin/buj/tl/ITranslationRuntime.kt | 13 + .../kotlin/buj/tl/ITranslationScriptParser.kt | 5 + src/main/kotlin/buj/tl/Tl.kt | 1027 +---------------- .../buj/tl/TranslationParserAssembly.kt | 29 + .../tl/TranslationRuntimeInfrastructure.kt | 24 + src/main/kotlin/buj/tl/ast/ColorPalette.kt | 12 + .../kotlin/buj/tl/ast/ColorScopeRenderer.kt | 48 + src/main/kotlin/buj/tl/ast/ScrCombo.kt | 16 + src/main/kotlin/buj/tl/ast/ScrEach.kt | 25 + src/main/kotlin/buj/tl/ast/ScrIf.kt | 119 ++ src/main/kotlin/buj/tl/ast/ScrKey.kt | 12 + src/main/kotlin/buj/tl/ast/ScrNone.kt | 7 + src/main/kotlin/buj/tl/ast/ScrText.kt | 7 + src/main/kotlin/buj/tl/lexer/SpanModel.kt | 240 ++++ .../buj/tl/locale/LocaleColorPalette.kt | 19 + src/main/kotlin/buj/tl/locale/LocaleFile.kt | 182 +++ .../kotlin/buj/tl/locale/LocaleNormalizer.kt | 12 + src/main/kotlin/buj/tl/parser/ParseEach.kt | 52 + .../kotlin/buj/tl/parser/ParseExpression.kt | 92 ++ src/main/kotlin/buj/tl/parser/ParseIf.kt | 34 + src/main/kotlin/buj/tl/parser/ParseKey.kt | 20 + .../kotlin/buj/tl/parser/ParseOperator.kt | 26 + src/main/kotlin/buj/tl/parser/ParseRoot.kt | 61 + src/main/kotlin/buj/tl/parser/ParseUnicode.kt | 36 + .../buj/tl/tokenizer/ITranslationTokenizer.kt | 5 + .../buj/tl/tokenizer/TranslationTokenizer.kt | 12 + .../mindurka/api/EventDispatchStrategy.kt | 20 + src/main/kotlin/mindurka/api/Events.kt | 66 +- src/main/kotlin/mindurka/api/Gamemode.kt | 75 +- src/main/kotlin/mindurka/api/ICancellable.kt | 10 + .../mindurka/api/IEventDispatchStrategy.kt | 3 + src/main/kotlin/mindurka/api/IMapHandle.kt | 11 + src/main/kotlin/mindurka/api/IMapManager.kt | 14 + .../kotlin/mindurka/api/ISpectateManager.kt | 13 + .../kotlin/mindurka/api/ITimerScheduler.kt | 10 + src/main/kotlin/mindurka/api/Timer.kt | 12 +- .../bootstrap/ApplicationBootstrap.kt | 89 ++ .../mindurka/config/ConfigurationContracts.kt | 7 + .../config/CorePluginConfigurationPipeline.kt | 76 ++ .../config/CorePluginConfigurationRegistry.kt | 18 + .../mindurka/config/IConfigurationLoader.kt | 3 + .../mindurka/config/IConfigurationProvider.kt | 3 + .../mindurka/config/IConfigurationRegistry.kt | 8 + .../mindurka/config/IConfigurationResolver.kt | 3 + .../mindurka/config/IConfigurationSource.kt | 3 + .../mindurka/config/ISharedConfigLoader.kt | 3 + .../mindurka/config/ISharedConfigProvider.kt | 3 + .../mindurka/config/ISharedConfigRegistry.kt | 3 + .../mindurka/config/ISharedConfigSource.kt | 3 + .../kotlin/mindurka/config/SharedConfig.kt | 33 +- .../mindurka/config/SharedConfigAssembly.kt | 77 ++ .../ChatInitializationCoordinator.kt | 5 + .../coreplugin/CommandMessageNormalizer.kt | 12 + src/main/kotlin/mindurka/coreplugin/Config.kt | 23 +- .../kotlin/mindurka/coreplugin/CorePlugin.kt | 45 +- .../mindurka/coreplugin/GoogleTranslator.kt | 8 +- .../coreplugin/GoogleTranslatorProvider.kt | 14 + .../mindurka/coreplugin/HubDiscovery.kt | 6 +- .../coreplugin/HubDiscoveryGateway.kt | 6 + .../IChatInitializationCoordinator.kt | 3 + .../coreplugin/ICommandMessageNormalizer.kt | 3 + .../mindurka/coreplugin/IGoogleTranslator.kt | 6 + .../coreplugin/IHubDiscoveryGateway.kt | 6 + .../coreplugin/IModerationActionPolicy.kt | 5 + .../coreplugin/IPlayerDataProvider.kt | 8 + .../coreplugin/IPluginLaunchCoordinator.kt | 3 + .../mindurka/coreplugin/IRabbitMqLifecycle.kt | 3 + src/main/kotlin/mindurka/coreplugin/Main.kt | 4 +- .../mindurka/coreplugin/ModCommandHandler.kt | 12 +- .../coreplugin/ModerationActionPolicy.kt | 5 + .../mindurka/coreplugin/ModerationActions.kt | 7 +- .../kotlin/mindurka/coreplugin/PlayerData.kt | 8 +- .../mindurka/coreplugin/PlayerDataProvider.kt | 8 + .../coreplugin/PluginLaunchCoordinator.kt | 9 + .../kotlin/mindurka/coreplugin/Protocol.kt | 5 +- .../mindurka/coreplugin/RabbitMqLifecycle.kt | 6 + .../coreplugin/commands/CommandConstraint.kt | 5 +- .../coreplugin/commands/CommandRegistry.kt | 16 + .../mindurka/coreplugin/commands/Commands.kt | 7 +- .../coreplugin/commands/ICommandConstraint.kt | 8 + .../coreplugin/commands/ICommandRegistry.kt | 10 + .../contracts/EnterpriseContracts.kt | 11 + .../contracts/IApplicationBootstrap.kt | 3 + .../contracts/IApplicationBootstrapFactory.kt | 3 + .../IApplicationBootstrapProvider.kt | 3 + .../IApplicationBootstrapSelector.kt | 3 + .../contracts/IApplicationLaunchStrategy.kt | 3 + .../contracts/IComponentRegistry.kt | 8 + .../contracts/IComponentResolver.kt | 5 + .../contracts/ICorePluginSubsystem.kt | 3 + .../ICorePluginSubsystemExecutionStrategy.kt | 3 + .../contracts/ICorePluginSubsystemFactory.kt | 3 + .../contracts/ICorePluginSubsystemProvider.kt | 3 + .../contracts/ICorePluginSubsystemRegistry.kt | 3 + .../contracts/ICorePluginSubsystemResolver.kt | 3 + .../contracts/ICorePluginSubsystemSelector.kt | 3 + .../contracts/ILifecycleCoordinator.kt | 3 + .../coreplugin/contracts/ILifecyclePhase.kt | 3 + .../contracts/SubsystemContracts.kt | 9 + .../database/DatabaseLifecycleProvider.kt | 9 + .../database/IDatabaseLifecycleProvider.kt | 5 + .../extern/ExternalServerGateway.kt | 24 + .../mindurka/coreplugin/extern/HeaderI.kt | 24 +- .../extern/IExternalServerGateway.kt | 11 + .../coreplugin/factory/SubsystemAssembly.kt | 46 + .../messages/IMessageTypeRegistry.kt | 9 + .../messages/MessageTypeRegistry.kt | 21 + .../CorePluginInitializationPipelines.kt | 20 + .../pipeline/CorePluginSubsystemPipeline.kt | 14 + .../coreplugin/protocol/IProtocolFactory.kt | 7 + .../protocol/IProtocolFactoryProvider.kt | 3 + .../protocol/IProtocolFactorySelector.kt | 3 + .../coreplugin/protocol/IProtocolNetState.kt | 3 + .../protocol/ProtocolFactoryAssembly.kt | 22 + .../recording/IRecordingLifecycle.kt | 5 + .../mindurka/coreplugin/recording/Mod.kt | 5 +- .../RecordingLifecycleCoordinator.kt | 7 + .../coreplugin/registry/EnterpriseRegistry.kt | 25 + .../coreplugin/registry/SubsystemRegistry.kt | 16 + .../strategy/SubsystemExecutionStrategy.kt | 16 + .../CommandInitializationSubsystem.kt | 26 + .../FeatureInitializationSubsystem.kt | 25 + .../InfrastructureInitializationSubsystem.kt | 22 + .../coreplugin/votes/IVoteResolutionPolicy.kt | 5 + .../kotlin/mindurka/coreplugin/votes/Vote.kt | 4 +- .../coreplugin/votes/VoteResolutionPolicy.kt | 10 + .../kotlin/mindurka/di/DependencyInjection.kt | 40 + src/main/kotlin/mindurka/ui/DialogRegistry.kt | 12 + src/main/kotlin/mindurka/ui/IDialog.kt | 3 + .../kotlin/mindurka/ui/IDialogRegistry.kt | 10 + src/main/kotlin/mindurka/ui/Ui.kt | 15 +- src/main/kotlin/mindurka/util/IRead.kt | 9 + src/main/kotlin/mindurka/util/ISendMessage.kt | 45 + src/main/kotlin/mindurka/util/IWrite.kt | 9 + src/main/kotlin/mindurka/util/Read.kt | 8 +- src/main/kotlin/mindurka/util/SendMessage.kt | 33 +- src/main/kotlin/mindurka/util/Write.kt | 8 +- 145 files changed, 2323 insertions(+), 1335 deletions(-) create mode 100644 src/main/kotlin/buj/tl/IL.kt create mode 100644 src/main/kotlin/buj/tl/ILVoidDone.kt create mode 100644 src/main/kotlin/buj/tl/IScript.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationLocaleRegistry.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationLocaleResolver.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationParserFactory.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationParserProvider.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationParserSelector.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationRuntime.kt create mode 100644 src/main/kotlin/buj/tl/ITranslationScriptParser.kt create mode 100644 src/main/kotlin/buj/tl/TranslationParserAssembly.kt create mode 100644 src/main/kotlin/buj/tl/TranslationRuntimeInfrastructure.kt create mode 100644 src/main/kotlin/buj/tl/ast/ColorPalette.kt create mode 100644 src/main/kotlin/buj/tl/ast/ColorScopeRenderer.kt create mode 100644 src/main/kotlin/buj/tl/ast/ScrCombo.kt create mode 100644 src/main/kotlin/buj/tl/ast/ScrEach.kt create mode 100644 src/main/kotlin/buj/tl/ast/ScrIf.kt create mode 100644 src/main/kotlin/buj/tl/ast/ScrKey.kt create mode 100644 src/main/kotlin/buj/tl/ast/ScrNone.kt create mode 100644 src/main/kotlin/buj/tl/ast/ScrText.kt create mode 100644 src/main/kotlin/buj/tl/lexer/SpanModel.kt create mode 100644 src/main/kotlin/buj/tl/locale/LocaleColorPalette.kt create mode 100644 src/main/kotlin/buj/tl/locale/LocaleFile.kt create mode 100644 src/main/kotlin/buj/tl/locale/LocaleNormalizer.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseEach.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseExpression.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseIf.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseKey.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseOperator.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseRoot.kt create mode 100644 src/main/kotlin/buj/tl/parser/ParseUnicode.kt create mode 100644 src/main/kotlin/buj/tl/tokenizer/ITranslationTokenizer.kt create mode 100644 src/main/kotlin/buj/tl/tokenizer/TranslationTokenizer.kt create mode 100644 src/main/kotlin/mindurka/api/EventDispatchStrategy.kt create mode 100644 src/main/kotlin/mindurka/api/ICancellable.kt create mode 100644 src/main/kotlin/mindurka/api/IEventDispatchStrategy.kt create mode 100644 src/main/kotlin/mindurka/api/IMapHandle.kt create mode 100644 src/main/kotlin/mindurka/api/IMapManager.kt create mode 100644 src/main/kotlin/mindurka/api/ISpectateManager.kt create mode 100644 src/main/kotlin/mindurka/api/ITimerScheduler.kt create mode 100644 src/main/kotlin/mindurka/bootstrap/ApplicationBootstrap.kt create mode 100644 src/main/kotlin/mindurka/config/ConfigurationContracts.kt create mode 100644 src/main/kotlin/mindurka/config/CorePluginConfigurationPipeline.kt create mode 100644 src/main/kotlin/mindurka/config/CorePluginConfigurationRegistry.kt create mode 100644 src/main/kotlin/mindurka/config/IConfigurationLoader.kt create mode 100644 src/main/kotlin/mindurka/config/IConfigurationProvider.kt create mode 100644 src/main/kotlin/mindurka/config/IConfigurationRegistry.kt create mode 100644 src/main/kotlin/mindurka/config/IConfigurationResolver.kt create mode 100644 src/main/kotlin/mindurka/config/IConfigurationSource.kt create mode 100644 src/main/kotlin/mindurka/config/ISharedConfigLoader.kt create mode 100644 src/main/kotlin/mindurka/config/ISharedConfigProvider.kt create mode 100644 src/main/kotlin/mindurka/config/ISharedConfigRegistry.kt create mode 100644 src/main/kotlin/mindurka/config/ISharedConfigSource.kt create mode 100644 src/main/kotlin/mindurka/config/SharedConfigAssembly.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/ChatInitializationCoordinator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/CommandMessageNormalizer.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/GoogleTranslatorProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/HubDiscoveryGateway.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IChatInitializationCoordinator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/ICommandMessageNormalizer.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IGoogleTranslator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IHubDiscoveryGateway.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IModerationActionPolicy.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IPlayerDataProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IPluginLaunchCoordinator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/IRabbitMqLifecycle.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/ModerationActionPolicy.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/PlayerDataProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/PluginLaunchCoordinator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/RabbitMqLifecycle.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/commands/CommandRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/commands/ICommandConstraint.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/commands/ICommandRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/EnterpriseContracts.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IApplicationBootstrap.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IApplicationBootstrapFactory.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IApplicationBootstrapProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IApplicationBootstrapSelector.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IApplicationLaunchStrategy.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IComponentRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/IComponentResolver.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystem.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystemExecutionStrategy.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystemFactory.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystemProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystemRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystemResolver.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ICorePluginSubsystemSelector.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ILifecycleCoordinator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/ILifecyclePhase.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/contracts/SubsystemContracts.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/database/DatabaseLifecycleProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/database/IDatabaseLifecycleProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/extern/ExternalServerGateway.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/extern/IExternalServerGateway.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/factory/SubsystemAssembly.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/messages/IMessageTypeRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/messages/MessageTypeRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/pipeline/CorePluginInitializationPipelines.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/pipeline/CorePluginSubsystemPipeline.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/protocol/IProtocolFactory.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/protocol/IProtocolFactoryProvider.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/protocol/IProtocolFactorySelector.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/protocol/IProtocolNetState.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/protocol/ProtocolFactoryAssembly.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/recording/IRecordingLifecycle.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/recording/RecordingLifecycleCoordinator.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/registry/EnterpriseRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/registry/SubsystemRegistry.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/strategy/SubsystemExecutionStrategy.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/subsystems/CommandInitializationSubsystem.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/subsystems/FeatureInitializationSubsystem.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/subsystems/InfrastructureInitializationSubsystem.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/votes/IVoteResolutionPolicy.kt create mode 100644 src/main/kotlin/mindurka/coreplugin/votes/VoteResolutionPolicy.kt create mode 100644 src/main/kotlin/mindurka/di/DependencyInjection.kt create mode 100644 src/main/kotlin/mindurka/ui/DialogRegistry.kt create mode 100644 src/main/kotlin/mindurka/ui/IDialog.kt create mode 100644 src/main/kotlin/mindurka/ui/IDialogRegistry.kt create mode 100644 src/main/kotlin/mindurka/util/IRead.kt create mode 100644 src/main/kotlin/mindurka/util/ISendMessage.kt create mode 100644 src/main/kotlin/mindurka/util/IWrite.kt diff --git a/src/main/kotlin/buj/tl/IL.kt b/src/main/kotlin/buj/tl/IL.kt new file mode 100644 index 0000000..5b8e59e --- /dev/null +++ b/src/main/kotlin/buj/tl/IL.kt @@ -0,0 +1,6 @@ +package buj.tl + +interface IL> { + fun put(key: String, value: Script): Self + fun put(key: String, text: String): Self +} diff --git a/src/main/kotlin/buj/tl/ILVoidDone.kt b/src/main/kotlin/buj/tl/ILVoidDone.kt new file mode 100644 index 0000000..9d561b3 --- /dev/null +++ b/src/main/kotlin/buj/tl/ILVoidDone.kt @@ -0,0 +1,5 @@ +package buj.tl + +interface ILVoidDone> : IL { + fun done(key: String) +} diff --git a/src/main/kotlin/buj/tl/IScript.kt b/src/main/kotlin/buj/tl/IScript.kt new file mode 100644 index 0000000..79231f6 --- /dev/null +++ b/src/main/kotlin/buj/tl/IScript.kt @@ -0,0 +1,6 @@ +package buj.tl + +interface IScript { + fun append(ctx: LCtx, source: String, lang: String): String + fun debug(): String +} diff --git a/src/main/kotlin/buj/tl/ITranslationLocaleRegistry.kt b/src/main/kotlin/buj/tl/ITranslationLocaleRegistry.kt new file mode 100644 index 0000000..1b21a97 --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationLocaleRegistry.kt @@ -0,0 +1,6 @@ +package buj.tl + +interface ITranslationLocaleRegistry { + fun register(loader: ClassLoader) + fun all(): List +} diff --git a/src/main/kotlin/buj/tl/ITranslationLocaleResolver.kt b/src/main/kotlin/buj/tl/ITranslationLocaleResolver.kt new file mode 100644 index 0000000..db35262 --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationLocaleResolver.kt @@ -0,0 +1,5 @@ +package buj.tl + +interface ITranslationLocaleResolver { + fun resolve(locale: String, key: String): Script +} diff --git a/src/main/kotlin/buj/tl/ITranslationParserFactory.kt b/src/main/kotlin/buj/tl/ITranslationParserFactory.kt new file mode 100644 index 0000000..9f361b1 --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationParserFactory.kt @@ -0,0 +1,3 @@ +package buj.tl + +interface ITranslationParserFactory { fun create(): ITranslationScriptParser } diff --git a/src/main/kotlin/buj/tl/ITranslationParserProvider.kt b/src/main/kotlin/buj/tl/ITranslationParserProvider.kt new file mode 100644 index 0000000..a980596 --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationParserProvider.kt @@ -0,0 +1,3 @@ +package buj.tl + +interface ITranslationParserProvider { fun provide(): ITranslationParserFactory } diff --git a/src/main/kotlin/buj/tl/ITranslationParserSelector.kt b/src/main/kotlin/buj/tl/ITranslationParserSelector.kt new file mode 100644 index 0000000..ea5b62f --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationParserSelector.kt @@ -0,0 +1,3 @@ +package buj.tl + +interface ITranslationParserSelector { fun select(): ITranslationParserProvider } diff --git a/src/main/kotlin/buj/tl/ITranslationRuntime.kt b/src/main/kotlin/buj/tl/ITranslationRuntime.kt new file mode 100644 index 0000000..58742ec --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationRuntime.kt @@ -0,0 +1,13 @@ +package buj.tl + +import mindustry.gen.Player + +interface ITranslationRuntime { + fun broadcast(): La + fun send(player: Player): Lc + fun fmtFor(player: Player): Ls + fun fmt(locale: String): Ls + fun fmt(player: Player): Ls + fun init(loader: ClassLoader) + fun parse(script: String): Script +} diff --git a/src/main/kotlin/buj/tl/ITranslationScriptParser.kt b/src/main/kotlin/buj/tl/ITranslationScriptParser.kt new file mode 100644 index 0000000..44775f7 --- /dev/null +++ b/src/main/kotlin/buj/tl/ITranslationScriptParser.kt @@ -0,0 +1,5 @@ +package buj.tl + +interface ITranslationScriptParser { + fun parse(source: String): Script +} diff --git a/src/main/kotlin/buj/tl/Tl.kt b/src/main/kotlin/buj/tl/Tl.kt index f3ba86b..e538bea 100644 --- a/src/main/kotlin/buj/tl/Tl.kt +++ b/src/main/kotlin/buj/tl/Tl.kt @@ -9,262 +9,6 @@ import mindustry.gen.Groups import mindustry.gen.Player import java.io.IOException -private fun minIdx(vararg vals: Int): Int { - var min = -1 - for (v in vals) if (v != -1 && v < min || min == -1) min = v - return min -} - -private fun destructLocale(locale: String): Array { - val san = locale.replace(Regex("[^a-zA-Z0-9_-]"), "_") - .replace(Regex("_+"), "_") - .replace(Regex("^_|_$"), "") - .lowercase() - if (san.indexOf('_') > 0) return arrayOf(san, san.take(san.indexOf('_')), "c") - if (san != "c") return arrayOf(san, "c") - return arrayOf("c") -} -// @formatter:off -private val COLORS = arrayOf( - "clear", "black", "white", "lightgray", - "gray", "darkgray", "blue", "navy", - "royal", "slate", "sky", "cyan", - "teal", "green", "acid", "lime", - "forest", "olive", "yellow", "gold", - "goldenrod", "orange", "brown", "tan", - "brick", "red", "scarlet", "coral", - "salmon", "pink", "magenta", "purple", - "violet", "maroon", -) -// @formatter:on -private fun isValidColor(color: String): Boolean { - if (color.startsWith("#")) return color.matches(Regex("^#([0-9a-fA-F]{1,6}|[0-9a-fA-F]{8})$")) - return color in COLORS -} - -private val loaders = Seq() -private val localeCache = ObjectMap>() - -internal class LocaleFile { - companion object { - operator fun get(localeBase: String, key: String): Script { - var i = loaders.size - while (--i >= 0) { - val loader = loaders[i] - for (locale in destructLocale(localeBase)) { - val file = this[loader, locale] - if (file == null || !file.tls.containsKey(key)) continue - return file.tls.get(key) - } - } - return ScrText("[red]$key[]") - } - - operator fun get(loader: ClassLoader, locale: String): LocaleFile? { - val cache = localeCache.get(loader) { ObjectMap() } - if (cache.containsKey(locale)) { - return cache.get(locale) - } - - val str: String - try { - val stream = loader.getResourceAsStream("lang/${locale}.l") - if (stream == null) { - cache.put(locale, null) - return null - } - val bytes = stream.readBytes() - str = bytes.toString(Charsets.UTF_8) - } catch (_: IOException) { - return null - } - - val file = parse(str) - - cache.put(locale, file) - return file - } - - internal fun parse(str: String): LocaleFile { - val span = StringSpan(str) - - val file = LocaleFile() - var prefix = "" - var name = "" - var collection = TemplateSpanCollection() - - while (!span.isEmpty) { - span.trimStart() - - if (span.stripPrefix("#")) { - if (name.isNotEmpty()) { - if (file.tls.put(name, Tl.parse(collection.intoSpanCollection())) != null) throw RuntimeException("duplicate key $name") - collection = TemplateSpanCollection() - } - - name = "" - while (!span.isEmpty && span[0] != '\n') span.inc() - continue - } - - if (span.stripPrefix("[")) { - if (name.isNotEmpty()) { - if (file.tls.put(name, Tl.parse(collection.intoSpanCollection())) != null) throw RuntimeException("duplicate key $name") - collection = TemplateSpanCollection() - } - - name = "" - span.trimStart() - prefix = buildString { - while (!span.isEmpty && (span[0].isLetterOrDigit() || span[0] in "-_.")) append(span.next()) - } - span.trimStart() - if (!span.stripPrefix("]")) throw RuntimeException("unenclosed prefix statement at ${span.at}") - continue - } - - if (span.stripPrefix("=")) { - if (name.isEmpty()) throw RuntimeException("attempt to append a value despite not having an entry open") - - // It's fine since it's just one character - collection.growFrom(StringSpan("\n")) - span.stripPrefix(" ") - while (!span.isEmpty && span[0] != '\n') { - if (span[0] == '\r') { - span.inc() - continue - } - collection.growFrom(span) - span.inc() - } - continue - } - - // Both do not do the same thing anymore. - if (span.stripPrefix("-")) { - if (name.isEmpty()) throw RuntimeException("attempt to append a value despite not having an entry open") - - collection.growFrom(StringSpan(" ")) - span.stripPrefix(" ") - while (!span.isEmpty && span[0] != '\n') { - if (span[0] == '\r') { - span.inc() - continue - } - collection.growFrom(span) - span.inc() - } - continue - } - - if (span.stripPrefix(":")) { - if (name.isEmpty()) throw RuntimeException("attempt to append a value despite not having an entry open") - - span.stripPrefix(" ") - while (!span.isEmpty && span[0] != '\n') { - if (span[0] == '\r') { - span.inc() - continue - } - collection.growFrom(span) - span.inc() - } - continue - } - - if (name.isNotEmpty()) { - if (file.tls.put(name, Tl.parse(collection.intoSpanCollection())) != null) throw RuntimeException("duplicate key $name") - collection = TemplateSpanCollection() - } - - val at = span.at - - name = buildString { - while (!span.isEmpty && (span[0].isLetterOrDigit() || span[0] in "-_.")) append(span.next()) - } - - if (name.isEmpty()) continue - - name = (if (prefix.isEmpty()) { "" } else { "$prefix." }) + name - if (name.startsWith(".")) throw RuntimeException("entry name cannot start with a dot ($name) at $at") - if (name.endsWith(".")) throw RuntimeException("entry name cannot end with a dot ($name) at $at") - if (name.contains("..")) throw RuntimeException("entry name cannot contain 2 consecutive dots ($name) at $at") - - span.trimStart() - if (!span.stripPrefix("=")) throw RuntimeException("'=' must be used to assign a value to the entry at ${span.at}") - - val t = StringBuilder() - - span.stripPrefix(" ") - while (!span.isEmpty && span[0] != '\n') { - if (span[0] == '\r') { - span.inc() - continue - } - collection.growFrom(span) - span.inc() - } - } - - if (name.isNotEmpty()) { - if (file.tls.put(name, Tl.parse(collection.intoSpanCollection())) != null) throw RuntimeException("duplicate key $name") - } - - return file - } - } - - private val tls = ObjectMap() - - operator fun get(key: String): Script? = if (tls.containsKey(key)) tls[key] else null -} - -private fun encloseColors(s: String): String { - var s = s - - if (s.isEmpty()) return s - - var colorNestness = 0 - var ptr = 0 - - while (run { ptr = s.indexOf('[', ptr); ptr } != -1) { - val start = ptr - ptr = s.indexOf(']', ptr) - if (ptr == -1) break - - val maybeColor = s.substring(start + 1, ptr) - if (maybeColor.contains('[')) { - ptr = start + 1 + maybeColor.indexOf('[') - continue - } - if (isValidColor(maybeColor)) colorNestness += 1 - else if (start + 1 == ptr) { - if (colorNestness == 0) { - s = if (ptr + 1 == s.length) s.substring(0, start) - else s.substring(0, start) + s.substring(ptr + 1) - ptr -= 2 - } else { - colorNestness -= 1 - } - } - } - - return closeColors(s) + run { val b = StringBuilder(colorNestness * 2); repeat(colorNestness) { b.append("[]") }; b } -} - -private fun closeColors(s: String): String { - if (s.isEmpty()) return s - - var ptr = s.length - 1 - while ((s[ptr] in 'a'..'f' || s[ptr] in 'A'..'F' || s[ptr] == '#') && ptr > 0) ptr-- - if (s[ptr] != '[') return s - val start = ptr - while (s[ptr] == '[' && ptr > 0) ptr-- - if ((start - ptr) % 2 == 1) return s - - return s.substring(0, start) + "[" -} - class LCtx(private val parent: LCtx? = null) { private val tls = ObjectMap() @@ -280,20 +24,12 @@ class LCtx(private val parent: LCtx? = null) { fun tl(key: String, lang: String): Script { if (tls.containsKey(key)) return tls[key] - return LocaleFile[lang, key] + return Tl.resolve(lang, key) } } -interface L> { - /** Add a mapping for a translation key. */ - fun put(key: String, value: Script): Self - /** Set translation key to an unformatted text. */ - fun put(key: String, text: String): Self -} - -interface LVoidDone> : L { - fun done(key: String) -} +typealias L = IL +typealias LVoidDone = ILVoidDone class La(val ctx: LCtx = LCtx()) : LVoidDone { /** Add a mapping for a translation key. */ @@ -352,730 +88,7 @@ class Ls(val locale: String, val ctx: LCtx = LCtx()) : L { } } -interface Script { - fun append(ctx: LCtx, source: String, lang: String): String - fun debug(): String -} - -private class ScrCombo(val list: Seq