Skip to content

Conversation

@sya-ri
Copy link
Owner

@sya-ri sya-ri commented Jan 6, 2026

Changelog

Added

  • Added support for serialization of sealed classes and interfaces.
    • Added discriminator property to the @KtConfig annotation for handling sealed hierarchies.
  • Added new methods to KtConfigLoader for easier file handling:
    • loadAndSave: Loads a file and immediately saves it back.
    • loadAndSaveIfNotExists: Loads a file and saves default values if the file doesn't exist.
    • saveIfNotExists: Saves the configuration only if the file does not already exist.
  • Added FormattedColorSerializer#isSupportedAlpha property to detect Minecraft version support for an alpha channel in colors.

Changed

  • Improved the KSP code generator to use explicit imports instead of fully qualified names in generated loader classes.
    • This results in cleaner and more readable generated code.

    • Example
        // Target
        @KtConfig
        data class ExampleConfig(
            val string: String,
            val list: List<String>,
        )
        
        // Before
        private val ListOfString: Serializer<List<String>> =
            dev.s7a.ktconfig.serializer.ListSerializer(dev.s7a.ktconfig.serializer.StringSerializer)
      
        override fun load(configuration: YamlConfiguration, parentPath: String): ExampleConfig = ExampleConfig(
          dev.s7a.ktconfig.serializer.StringSerializer.getOrThrow(configuration, "${parentPath}string"),
          ListOfString.getOrThrow(configuration, "${parentPath}list"),
        )
      
        // After
        private val ListOfString: Serializer<List<String>> = ListSerializer(StringSerializer)
      
        override fun load(configuration: YamlConfiguration, parentPath: String): ExampleConfig = ExampleConfig(
          StringSerializer.getOrThrow(configuration, "${parentPath}string"),
          ListOfString.getOrThrow(configuration, "${parentPath}list"),
        )
  • Deprecated @PathName and replaced it with @SerialName for better consistency.
    • @PathName is scheduled to be removed in v2.2.0.
  • Fixed FormattedColorSerializer to ignore alpha values of 255 (fully opaque) when encoding colors, treating them as if no alpha channel is specified.

Fixed

  • Fixed FormattedColorSerializer to ignore an alpha channel when encoding colors on Minecraft versions that don't support alpha transparency.

sya-ri added 5 commits January 5, 2026 10:22
- Implemented sealed serialization support in `KtConfig`.
- Added `discriminator` property to `@KtConfig` annotations for sealed hierarchy handling.
- Updated `KtConfigSymbolProcessor` to generate loaders for sealed classes and interfaces.
- Introduced tests for sealed serializers and extended functionality in `ExamplePlugin`.
- Removed unused `mavenPublish` version from `libs.versions.toml`.
- Replaced the `@PathName` annotation with `@SerialName` for consistency and unification of functionality.
- Marked `@PathName` as deprecated starting from version 2.1.0, with removal scheduled in version 2.2.0.
- Updated related documentation, inline comments, and migration examples (`README.md` and `DEPRECATION.md`).
- Removed the `getPathName` method and updated its usages to `getSerialName`.
@sya-ri sya-ri changed the title Release: v2.1.0 Release v2.1.0 Jan 6, 2026
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Code Coverage

File Coverage [51.52%]
src/main/kotlin/dev/s7a/ktconfig/KtConfigLoader.kt 87.18%
src/main/kotlin/dev/s7a/ktconfig/exception/InvalidDiscriminatorException.kt 0.00%
src/main/kotlin/dev/s7a/ktconfig/type/FormattedColor.kt 0.00%
Total Project Coverage 66.34%

@sya-ri sya-ri marked this pull request as draft January 7, 2026 05:05
sya-ri added 9 commits January 7, 2026 14:19
- Implemented `FormattedColorSerializer` for color parsing with ARGB/hexadecimal formats.
- Added version-specific alpha channel handling based on Minecraft API compatibility.
- Updated `ExamplePlugin` to include tests for `FormattedColorSerializer`.
- Replaced dependency `spigot8` with `spigot` for broader compatibility.
- Moved built-in and custom serializer definitions to a new `Serializer` module for better reusability and maintainability.
- Replaced inline serializer logic within `KtConfigSymbolProcessor` with references to `Serializer`.
- Simplified type-based serializer resolution using `Serializer.findSerializer`.
- Removed redundant and deprecated serializer methods, including `getComment` and `getPathName`.
- Updated `build.gradle.kts` to use the new localization for server JAR URLs.
- Deleted the `Discriminator` interface and its implementations as they were no longer utilized.
- Added `getSealedSubclassesDeeply` to recursively retrieve all leaf subclasses in a sealed class hierarchy.
- Updated `ExamplePlugin` to refine handling of sealed serializers and discriminator usage.
- Updated `build.gradle.kts` to conditionally resolve server JAR URLs based on the specified Minecraft version.
- Added error handling for unsupported or unknown versions.
- Extracted reusable `addControlFlowCode` and `asLiteralList` utilities to a new helper file, `KotlinPoetHelpers.kt`.
- Simplified `KtConfigSymbolProcessor` by replacing inline control flow and list building logic with helper methods.
- Removed redundant imports (`joinToCode`) and improved consistency in generated code.
…rove generated code readability

- Replaced fully qualified serializer names with `ClassName` instances in `Serializer`.
- Refactored `Parameter.Serializer` to utilize `CodeBlock` for initializer generation.
- Updated `KtConfigSymbolProcessor` to use cleaner imports and references, reducing noise in generated loader classes.
@sya-ri
Copy link
Owner Author

sya-ri commented Jan 7, 2026

Update SNAPSHOT

sya-ri added 2 commits January 8, 2026 00:18
- Introduced `loadAndSave` for loading a file and immediately saving it back, useful for normalizing configuration files.
- Added `loadAndSaveIfNotExists` to load a file and create it with default values if absent.
- Implemented `saveIfNotExists` to save configurations only when the file doesn't exist.
- Updated `KtConfigLoaderTest` with comprehensive tests for the new methods.
@sya-ri
Copy link
Owner Author

sya-ri commented Jan 7, 2026

Update SNAPSHOT

@sya-ri sya-ri self-assigned this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants