DEADSOFTWARE

Game action modules generation
authorfredboy <fredboy@protonmail.com>
Tue, 14 May 2024 17:25:11 +0000 (00:25 +0700)
committerfredboy <fredboy@protonmail.com>
Tue, 14 May 2024 17:25:11 +0000 (00:25 +0700)
33 files changed:
core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/UseBlockActionsModule.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/UseItemActionsModule.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/IPlaceBlockAction.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSnowedGrassAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useblock/IUseBlockAction.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseBlockAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseChestAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseCraftingTableAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseFurnaceAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/IUseItemAction.kt [deleted file]
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseEmptyBucketAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseItemAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseLavaBucketAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UsePigSpawnEggAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseWaterBucketAction.kt
dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateMapMultibindingsModule.kt [new file with mode: 0644]
dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateMapMultibindingsSymbolProcessor.kt [new file with mode: 0644]
dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateMapMultibindingsSymbolProcessorProvider.kt [new file with mode: 0644]
dagger-multibind-ksp/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider

diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt
deleted file mode 100644 (file)
index f2c5a23..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions
-
-import dagger.Binds
-import dagger.Module
-import dagger.multibindings.IntoMap
-import dagger.multibindings.StringKey
-import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.actions.placeblock.IPlaceBlockAction
-import ru.deadsoftware.cavedroid.game.actions.placeblock.PlaceBlockItemToBackgroundAction
-import ru.deadsoftware.cavedroid.game.actions.placeblock.PlaceBlockItemToForegroundAction
-import ru.deadsoftware.cavedroid.game.actions.placeblock.PlaceSlabAction
-
-@Module
-class PlaceBlockActionsModule {
-
-    @Binds
-    @IntoMap
-    @StringKey(PlaceBlockItemToForegroundAction.ACTION_KEY)
-    @GameScope
-    fun bindPlaceBlockItemToForegroundAction(action: PlaceBlockItemToForegroundAction): IPlaceBlockAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(PlaceBlockItemToBackgroundAction.ACTION_KEY)
-    @GameScope
-    fun bindPlaceBlockItemToBackgroundAction(action: PlaceBlockItemToBackgroundAction): IPlaceBlockAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(PlaceSlabAction.ACTION_KEY)
-    @GameScope
-    fun bindPlaceSlabAction(action: PlaceSlabAction): IPlaceBlockAction {
-        return action
-    }
-
-}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt
deleted file mode 100644 (file)
index 6f0fc0f..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions
-
-import dagger.Binds
-import dagger.Module
-import dagger.multibindings.IntoMap
-import dagger.multibindings.StringKey
-import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.actions.updateblock.*
-
-@Module
-class UpdateBlockActionsModule {
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateSandAction.BLOCK_KEY)
-    @GameScope
-    fun bindUpdateSandAction(action: UpdateSandAction): IUpdateBlockAction {
-        return action;
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateGravelAction.BLOCK_KEY)
-    @GameScope
-    fun bindUpdateGravelAction(action: UpdateGravelAction): IUpdateBlockAction {
-        return action;
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateRequiresBlockAction.ACTION_KEY)
-    @GameScope
-    fun bindUpdateRequiresBlockAction(action: UpdateRequiresBlockAction): IUpdateBlockAction {
-        return action;
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateGrassAction.BLOCK_KEY)
-    @GameScope
-    fun bindUpdateGrassAction(action: UpdateGrassAction): IUpdateBlockAction {
-        return action;
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateSnowedGrassAction.BLOCK_KEY)
-    @GameScope
-    fun bindUpdateSnowedGrassAction(action: UpdateSnowedGrassAction): IUpdateBlockAction {
-        return action;
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateBedLeftAction.BLOCK_KEY)
-    @GameScope
-    fun bindUpdateBedLeftAction(action: UpdateBedLeftAction): IUpdateBlockAction {
-        return action;
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UpdateBedRightAction.BLOCK_KEY)
-    @GameScope
-    fun bindUpdateBedRightAction(action: UpdateBedRightAction): IUpdateBlockAction {
-        return action;
-    }
-}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/UseBlockActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/UseBlockActionsModule.kt
deleted file mode 100644 (file)
index 7458dfc..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions
-
-import dagger.Binds
-import dagger.Module
-import dagger.multibindings.IntoMap
-import dagger.multibindings.StringKey
-import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.actions.useblock.IUseBlockAction
-import ru.deadsoftware.cavedroid.game.actions.useblock.UseChestAction
-import ru.deadsoftware.cavedroid.game.actions.useblock.UseCraftingTableAction
-import ru.deadsoftware.cavedroid.game.actions.useblock.UseFurnaceAction
-
-@Module
-class UseBlockActionsModule {
-
-    @Binds
-    @IntoMap
-    @StringKey(UseCraftingTableAction.KEY)
-    @GameScope
-    fun bindUseCraftingTableAction(action: UseCraftingTableAction): IUseBlockAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UseFurnaceAction.KEY)
-    @GameScope
-    fun bindUseFurnaceTableAction(action: UseFurnaceAction): IUseBlockAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UseChestAction.KEY)
-    @GameScope
-    fun bindUseChestAction(action: UseChestAction): IUseBlockAction {
-        return action
-    }
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/UseItemActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/UseItemActionsModule.kt
deleted file mode 100644 (file)
index d5e4f4f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions
-
-import dagger.Binds
-import dagger.Module
-import dagger.multibindings.IntoMap
-import dagger.multibindings.StringKey
-import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.actions.useitem.*
-
-@Module
-class UseItemActionsModule {
-
-    @Binds
-    @IntoMap
-    @StringKey(UseWaterBucketAction.ACTION_KEY)
-    @GameScope
-    fun bindUseWaterBucketAction(action: UseWaterBucketAction): IUseItemAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UseLavaBucketAction.ACTION_KEY)
-    @GameScope
-    fun bindUseLavaBucketAction(action: UseLavaBucketAction): IUseItemAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UseEmptyBucketAction.ACTION_KEY)
-    @GameScope
-    fun bindUseEmptyBucketAction(action: UseEmptyBucketAction): IUseItemAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UsePigSpawnEggAction.ACTION_KEY)
-    @GameScope
-    fun bindUsePigSpawnEgg(action: UsePigSpawnEggAction): IUseItemAction {
-        return action
-    }
-
-    @Binds
-    @IntoMap
-    @StringKey(UseBedAction.ACTION_KEY)
-    @GameScope
-    fun bindUseBedAction(action: UseBedAction): IUseItemAction {
-        return action
-    }
-
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/IPlaceBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/IPlaceBlockAction.kt
deleted file mode 100644 (file)
index 06c70c4..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions.placeblock
-
-import ru.deadsoftware.cavedroid.game.model.item.Item
-
-interface IPlaceBlockAction {
-
-    fun place(placeable: Item.Placeable, x: Int, y: Int)
-
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockAction.kt
new file mode 100644 (file)
index 0000000..e0f6cd8
--- /dev/null
@@ -0,0 +1,17 @@
+package ru.deadsoftware.cavedroid.game.actions.placeblock
+
+import ru.deadsoftware.cavedroid.game.model.item.Item
+import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+
+@GenerateMapMultibindingsModule(
+    interfaceClass = IPlaceBlockAction::class,
+    modulePackage = "ru.deadsoftware.cavedroid.game.actions",
+    moduleName = "PlaceBlockActionsModule"
+)
+annotation class PlaceBlockAction(val stringKey: String)
+
+interface IPlaceBlockAction {
+
+    fun place(placeable: Item.Placeable, x: Int, y: Int)
+
+}
index fdfb61a53008914d6ed9650c5931e204d58d677b..0a5399a0225c5edcb4203e0d9e0c618bf8066b70 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@PlaceBlockAction(stringKey = PlaceBlockItemToBackgroundAction.ACTION_KEY)
 class PlaceBlockItemToBackgroundAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val gameItemsHolder: GameItemsHolder,
index 22aafdd98e5c75a75aeb1a5fbc39c2317e5d5111..d3ff9797f6a528485dcf18b59479917ad8fb4d20 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@PlaceBlockAction(stringKey = PlaceBlockItemToForegroundAction.ACTION_KEY)
 class PlaceBlockItemToForegroundAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val placeSlabAction: PlaceSlabAction,
index 6ac94c98edfafd03a86b188a79ab004cc01180ed..3e0a185fee805a1fc803053ddb734178fae3f12a 100644 (file)
@@ -9,6 +9,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@PlaceBlockAction(stringKey = PlaceSlabAction.ACTION_KEY)
 class PlaceSlabAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
index 9cc4aeaa4f49211d4ce7d7c1387c2cb1faaf0b22..a397f1659bc54e59a3c58049b2d5a39e7b9d6a03 100644 (file)
@@ -1,5 +1,14 @@
 package ru.deadsoftware.cavedroid.game.actions.updateblock
 
+import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+
+@GenerateMapMultibindingsModule(
+    interfaceClass = IUpdateBlockAction::class,
+    modulePackage = "ru.deadsoftware.cavedroid.game.actions",
+    moduleName = "UpdateBlockActionsModule"
+)
+annotation class UpdateBlockAction(val stringKey: String)
+
 interface IUpdateBlockAction {
 
     fun update(x: Int, y: Int)
index 15621a25ae1c944193692dcd47efc1688c565bca..4e43f8f15e5832ecaff33e715bd555c21d40f1b7 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateBedLeftAction.BLOCK_KEY)
 class UpdateBedLeftAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val gameItemsHolder: GameItemsHolder,
index 4d47b357bbf9454de5d4c0a45393a55e60d79020..78e81fa01206b2dee256fadf0941e537929666c5 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateBedRightAction.BLOCK_KEY)
 class UpdateBedRightAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val gameItemsHolder: GameItemsHolder,
index d5ca3b161c242b97e1e6931ad0ee64f66ccc5d3c..56f814fdf38bbece9c12bd34472acda55c543d59 100644 (file)
@@ -6,6 +6,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateGrassAction.BLOCK_KEY)
 class UpdateGrassAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mGameItemsHolder: GameItemsHolder,
index 6cc026f0dbaa25551d30c28a6fee676b89d304ab..f51bc7fc7e46bf3f0733ddcd6fe032df1d716cac 100644 (file)
@@ -7,6 +7,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateGravelAction.BLOCK_KEY)
 class UpdateGravelAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
index 57172a5f24a7ef53408e4516b5aa7e3f3bc583eb..6b15a7acbc963ea7ec35a43008104628e2828e99 100644 (file)
@@ -5,6 +5,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateRequiresBlockAction.ACTION_KEY)
 class UpdateRequiresBlockAction @Inject constructor(
     private val gameWorld: GameWorld,
 ) : IUpdateBlockAction {
index 4a2b58e885c42fdbda8c71fadea87c2c065d4628..f2ef25ed941c6897237d2cb8fbc15701efebbad1 100644 (file)
@@ -7,6 +7,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateSandAction.BLOCK_KEY)
 class UpdateSandAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
index 0aa5c90f9ae94e66617bee224415ff71cac841b2..049c90b7b213f372592281c36274fe042205d05c 100644 (file)
@@ -6,6 +6,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UpdateBlockAction(stringKey = UpdateSnowedGrassAction.BLOCK_KEY)
 class UpdateSnowedGrassAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mGameItemsHolder: GameItemsHolder,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/IUseBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/IUseBlockAction.kt
deleted file mode 100644 (file)
index ddc70c5..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions.useblock
-
-import ru.deadsoftware.cavedroid.game.model.block.Block
-
-interface IUseBlockAction {
-
-    fun perform(block: Block, x: Int, y: Int)
-
-}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseBlockAction.kt
new file mode 100644 (file)
index 0000000..932bbf6
--- /dev/null
@@ -0,0 +1,17 @@
+package ru.deadsoftware.cavedroid.game.actions.useblock
+
+import ru.deadsoftware.cavedroid.game.model.block.Block
+import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+
+@GenerateMapMultibindingsModule(
+    interfaceClass = IUseBlockAction::class,
+    modulePackage = "ru.deadsoftware.cavedroid.game.actions",
+    moduleName = "UseBlockActionsModule"
+)
+annotation class UseBlockAction(val stringKey: String)
+
+interface IUseBlockAction {
+
+    fun perform(block: Block, x: Int, y: Int)
+
+}
\ No newline at end of file
index fa50c9428d4a81dab81eac4824efeee8b0ed7d03..fd370db74b862cd812ec225e531a77444f910718 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UseBlockAction(stringKey = UseChestAction.KEY)
 class UseChestAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val gameWindowsManager: GameWindowsManager,
index 3ce42b94f01ef0403e551ec2a80f5954cf14f1d7..de1112e9b8f4c707bd2c0b85d5a0df902573cb07 100644 (file)
@@ -6,6 +6,7 @@ import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
 import javax.inject.Inject
 
 @GameScope
+@UseBlockAction(stringKey = UseCraftingTableAction.KEY)
 class UseCraftingTableAction @Inject constructor(
     private val gameWindowsManager: GameWindowsManager
 ) : IUseBlockAction {
index 7c30402caf1aa29bb3f9ec1f5eff42bf3a66684b..1426263cbd66f8ecf766b5108a1c3ebc9fde48dc 100644 (file)
@@ -7,6 +7,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UseBlockAction(stringKey = UseFurnaceAction.KEY)
 class UseFurnaceAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val gameWindowsManager: GameWindowsManager,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/IUseItemAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/IUseItemAction.kt
deleted file mode 100644 (file)
index d963aee..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions.useitem
-
-import ru.deadsoftware.cavedroid.game.model.item.Item
-
-interface IUseItemAction {
-
-    fun perform(item: Item.Usable, x: Int, y: Int)
-
-}
\ No newline at end of file
index e0f9964a879c2d5c47bceadf2df3af25b46ab2ea..1aefd6745aaa3eb7bb35c2d84669093b059bda0c 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UseItemAction(UseBedAction.ACTION_KEY)
 class UseBedAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
index 57ca3f755305a5531b9cf972078d67e7cbcb6b48..fd64751e64f751bf24ed050cae6ae568561fe976 100644 (file)
@@ -9,6 +9,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UseItemAction(UseEmptyBucketAction.ACTION_KEY)
 class UseEmptyBucketAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseItemAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseItemAction.kt
new file mode 100644 (file)
index 0000000..be4d254
--- /dev/null
@@ -0,0 +1,17 @@
+package ru.deadsoftware.cavedroid.game.actions.useitem
+
+import ru.deadsoftware.cavedroid.game.model.item.Item
+import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+
+@GenerateMapMultibindingsModule(
+    interfaceClass = IUseItemAction::class,
+    modulePackage = "ru.deadsoftware.cavedroid.game.actions",
+    moduleName = "UseItemActionsModule"
+)
+annotation class UseItemAction(val stringKey: String)
+
+interface IUseItemAction {
+
+    fun perform(item: Item.Usable, x: Int, y: Int)
+
+}
\ No newline at end of file
index 965961711ee2ec08b44bf07961d8124322be7ea5..70438e3ac8406252b2ff120fb0577effdb06ea21 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UseItemAction(UseLavaBucketAction.ACTION_KEY)
 class UseLavaBucketAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
index 6c0c3ba714b098fca8390fc85649a91733d71cb4..4b2aa00406d93b5e332509031f50d7b17ae6d571 100644 (file)
@@ -9,6 +9,7 @@ import ru.deadsoftware.cavedroid.misc.utils.px
 import javax.inject.Inject
 
 @GameScope
+@UseItemAction(UsePigSpawnEggAction.ACTION_KEY)
 class UsePigSpawnEggAction @Inject constructor(
     private val mobsController: MobsController,
     private val gameItemsHolder: GameItemsHolder,
index 15e08fc77bd78962ec8fd6ccfd389a917cd66699..83b8f24f3670df9fbd05041fb5f5e0160831b6ed 100644 (file)
@@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
 
 @GameScope
+@UseItemAction(UseWaterBucketAction.ACTION_KEY)
 class UseWaterBucketAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val mobsController: MobsController,
diff --git a/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateMapMultibindingsModule.kt b/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateMapMultibindingsModule.kt
new file mode 100644 (file)
index 0000000..7a5b023
--- /dev/null
@@ -0,0 +1,14 @@
+package ru.fredboy.cavedroid.ksp.annotations
+
+import kotlin.reflect.KClass
+
+/**
+ * Annotation annotated with this must include stringKey parameter for key selection in generated module
+ */
+@Target(AnnotationTarget.ANNOTATION_CLASS)
+@Retention(AnnotationRetention.SOURCE)
+annotation class GenerateMapMultibindingsModule(
+    val interfaceClass: KClass<*>,
+    val modulePackage: String,
+    val moduleName: String,
+)
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateMapMultibindingsSymbolProcessor.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateMapMultibindingsSymbolProcessor.kt
new file mode 100644 (file)
index 0000000..cfaa3a5
--- /dev/null
@@ -0,0 +1,98 @@
+package ru.fredboy.cavedroid.ksp.processor
+
+import com.google.devtools.ksp.processing.*
+import com.google.devtools.ksp.symbol.KSAnnotated
+import com.google.devtools.ksp.symbol.KSClassDeclaration
+import com.google.devtools.ksp.symbol.KSType
+import com.squareup.kotlinpoet.*
+import com.squareup.kotlinpoet.ksp.toClassName
+import com.squareup.kotlinpoet.ksp.writeTo
+import ru.fredboy.cavedroid.ksp.annotations.GenerateMapMultibindingsModule
+
+class GenerateMapMultibindingsSymbolProcessor(
+    private val codeGenerator: CodeGenerator,
+    private val logger: KSPLogger,
+) : SymbolProcessor {
+
+    private fun generateModule(
+        annotationName: String,
+        interfaceName: ClassName,
+        moduleName: ClassName,
+        classes: List<KSClassDeclaration>
+    ): FileSpec? {
+        if (classes.isEmpty()) {
+            return null
+        }
+
+        val bindings = classes.map { decl ->
+            val stringKey = decl.annotations.first { declAnn ->
+                    declAnn.shortName.getShortName() == annotationName
+                }.arguments.firstOrNull { arg ->
+                    arg.name!!.getShortName() == "stringKey"
+                }?.value as? String ?: run {
+                    logger.error("@${annotationName} must include stringKey parameter for key selection in generated module")
+                    throw IllegalArgumentException()
+            }
+
+            val clazz = decl.toClassName()
+
+            FunSpec.builder("bind${clazz.simpleName}")
+                .addAnnotation(ClassName("dagger", "Binds"))
+                .addAnnotation(ClassName("dagger.multibindings", "IntoMap"))
+                .addAnnotation(
+                    AnnotationSpec.builder(ClassName("dagger.multibindings", "StringKey"))
+                        .addMember("\"$stringKey\"")
+                        .build()
+                )
+                .addParameter(ParameterSpec("impl", clazz))
+                .returns(interfaceName)
+                .addCode("return impl")
+                .build()
+        }
+
+        val moduleObject = TypeSpec.objectBuilder(moduleName)
+            .addAnnotation(ClassName("dagger", "Module"))
+            .addFunctions(bindings)
+            .build()
+
+        return FileSpec.builder(moduleName)
+            .addType(moduleObject)
+            .build()
+
+    }
+
+    private fun processAnnotation(resolver: Resolver, annotation: KSClassDeclaration) {
+        val args = annotation.annotations.first {
+            it.shortName.getShortName() == "GenerateMapMultibindingsModule"
+        }.arguments.takeIf { it.size == 3 } ?: run {
+            logger.error("GenerateMapMultibindingsModule should have 3 arguments")
+            throw IllegalArgumentException()
+        }
+
+        val interfaceName = args.first { it.name?.getShortName() == "interfaceClass" }.value as KSType
+        val modulePackage = args.first { it.name?.getShortName() == "modulePackage" }.value as String
+        val moduleName = args.first { it.name?.getShortName() == "moduleName" }.value as String
+
+        val moduleClassName = ClassName(modulePackage, moduleName)
+        val elements = resolver.getSymbolsWithAnnotation(annotation.qualifiedName!!.asString())
+            .filterIsInstance<KSClassDeclaration>()
+            .toList()
+
+        logger.info("Found elements: ${elements.joinToString()}")
+
+        generateModule(
+            annotationName = annotation.qualifiedName!!.getShortName(),
+            interfaceName = interfaceName.toClassName(),
+            moduleName = moduleClassName,
+            classes = elements
+        )?.writeTo(codeGenerator, Dependencies(true))
+    }
+
+    override fun process(resolver: Resolver): List<KSAnnotated> {
+        val annotations = resolver.getAnnotatedClasses(GenerateMapMultibindingsModule::class.qualifiedName!!, logger)
+        logger.info("Found annotations: ${annotations.joinToString { it.qualifiedName!!.asString() }}")
+        annotations.forEach { processAnnotation(resolver, it) }
+        return emptyList()
+    }
+
+}
\ No newline at end of file
diff --git a/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateMapMultibindingsSymbolProcessorProvider.kt b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateMapMultibindingsSymbolProcessorProvider.kt
new file mode 100644 (file)
index 0000000..49ea948
--- /dev/null
@@ -0,0 +1,17 @@
+package ru.fredboy.cavedroid.ksp.provider
+
+import com.google.devtools.ksp.processing.SymbolProcessor
+import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
+import com.google.devtools.ksp.processing.SymbolProcessorProvider
+import ru.fredboy.cavedroid.ksp.processor.GenerateMapMultibindingsSymbolProcessor
+
+internal class GenerateMapMultibindingsSymbolProcessorProvider : SymbolProcessorProvider {
+
+    override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
+        return GenerateMapMultibindingsSymbolProcessor(
+            codeGenerator = environment.codeGenerator,
+            logger = environment.logger,
+        )
+    }
+
+}
\ No newline at end of file