summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ef72467)
raw | patch | inline | side by side (parent: ef72467)
author | fredboy <fredboy@protonmail.com> | |
Tue, 14 May 2024 17:25:11 +0000 (00:25 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Tue, 14 May 2024 17:25:11 +0000 (00:25 +0700) |
33 files changed:
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt
+++ /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
+++ /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
+++ /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
+++ /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
+++ /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
--- /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)
+
+}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt
index fdfb61a53008914d6ed9650c5931e204d58d677b..0a5399a0225c5edcb4203e0d9e0c618bf8066b70 100644 (file)
--- a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt
+++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt
import javax.inject.Inject
@GameScope
+@PlaceBlockAction(stringKey = PlaceBlockItemToBackgroundAction.ACTION_KEY)
class PlaceBlockItemToBackgroundAction @Inject constructor(
private val gameWorld: GameWorld,
private val gameItemsHolder: GameItemsHolder,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt
index 22aafdd98e5c75a75aeb1a5fbc39c2317e5d5111..d3ff9797f6a528485dcf18b59479917ad8fb4d20 100644 (file)
--- a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt
+++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt
import javax.inject.Inject
@GameScope
+@PlaceBlockAction(stringKey = PlaceBlockItemToForegroundAction.ACTION_KEY)
class PlaceBlockItemToForegroundAction @Inject constructor(
private val gameWorld: GameWorld,
private val placeSlabAction: PlaceSlabAction,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt
index 6ac94c98edfafd03a86b188a79ab004cc01180ed..3e0a185fee805a1fc803053ddb734178fae3f12a 100644 (file)
import javax.inject.Inject
@GameScope
+@PlaceBlockAction(stringKey = PlaceSlabAction.ACTION_KEY)
class PlaceSlabAction @Inject constructor(
private val gameWorld: GameWorld,
private val mobsController: MobsController,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt
index 9cc4aeaa4f49211d4ce7d7c1387c2cb1faaf0b22..a397f1659bc54e59a3c58049b2d5a39e7b9d6a03 100644 (file)
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)
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt
index 15621a25ae1c944193692dcd47efc1688c565bca..4e43f8f15e5832ecaff33e715bd555c21d40f1b7 100644 (file)
import javax.inject.Inject
@GameScope
+@UpdateBlockAction(stringKey = UpdateBedLeftAction.BLOCK_KEY)
class UpdateBedLeftAction @Inject constructor(
private val gameWorld: GameWorld,
private val gameItemsHolder: GameItemsHolder,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt
index 4d47b357bbf9454de5d4c0a45393a55e60d79020..78e81fa01206b2dee256fadf0941e537929666c5 100644 (file)
import javax.inject.Inject
@GameScope
+@UpdateBlockAction(stringKey = UpdateBedRightAction.BLOCK_KEY)
class UpdateBedRightAction @Inject constructor(
private val gameWorld: GameWorld,
private val gameItemsHolder: GameItemsHolder,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt
index d5ca3b161c242b97e1e6931ad0ee64f66ccc5d3c..56f814fdf38bbece9c12bd34472acda55c543d59 100644 (file)
import javax.inject.Inject
@GameScope
+@UpdateBlockAction(stringKey = UpdateGrassAction.BLOCK_KEY)
class UpdateGrassAction @Inject constructor(
private val gameWorld: GameWorld,
private val mGameItemsHolder: GameItemsHolder,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt
index 6cc026f0dbaa25551d30c28a6fee676b89d304ab..f51bc7fc7e46bf3f0733ddcd6fe032df1d716cac 100644 (file)
import javax.inject.Inject
@GameScope
+@UpdateBlockAction(stringKey = UpdateGravelAction.BLOCK_KEY)
class UpdateGravelAction @Inject constructor(
private val gameWorld: GameWorld,
private val mobsController: MobsController,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt
index 57172a5f24a7ef53408e4516b5aa7e3f3bc583eb..6b15a7acbc963ea7ec35a43008104628e2828e99 100644 (file)
import javax.inject.Inject
@GameScope
+@UpdateBlockAction(stringKey = UpdateRequiresBlockAction.ACTION_KEY)
class UpdateRequiresBlockAction @Inject constructor(
private val gameWorld: GameWorld,
) : IUpdateBlockAction {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt
index 4a2b58e885c42fdbda8c71fadea87c2c065d4628..f2ef25ed941c6897237d2cb8fbc15701efebbad1 100644 (file)
import javax.inject.Inject
@GameScope
+@UpdateBlockAction(stringKey = UpdateSandAction.BLOCK_KEY)
class UpdateSandAction @Inject constructor(
private val gameWorld: GameWorld,
private val mobsController: MobsController,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSnowedGrassAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSnowedGrassAction.kt
index 0aa5c90f9ae94e66617bee224415ff71cac841b2..049c90b7b213f372592281c36274fe042205d05c 100644 (file)
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
+++ /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
--- /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
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseChestAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseChestAction.kt
index fa50c9428d4a81dab81eac4824efeee8b0ed7d03..fd370db74b862cd812ec225e531a77444f910718 100644 (file)
import javax.inject.Inject
@GameScope
+@UseBlockAction(stringKey = UseChestAction.KEY)
class UseChestAction @Inject constructor(
private val gameWorld: GameWorld,
private val gameWindowsManager: GameWindowsManager,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseCraftingTableAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseCraftingTableAction.kt
index 3ce42b94f01ef0403e551ec2a80f5954cf14f1d7..de1112e9b8f4c707bd2c0b85d5a0df902573cb07 100644 (file)
import javax.inject.Inject
@GameScope
+@UseBlockAction(stringKey = UseCraftingTableAction.KEY)
class UseCraftingTableAction @Inject constructor(
private val gameWindowsManager: GameWindowsManager
) : IUseBlockAction {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseFurnaceAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseFurnaceAction.kt
index 7c30402caf1aa29bb3f9ec1f5eff42bf3a66684b..1426263cbd66f8ecf766b5108a1c3ebc9fde48dc 100644 (file)
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
+++ /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
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt
index e0f9964a879c2d5c47bceadf2df3af25b46ab2ea..1aefd6745aaa3eb7bb35c2d84669093b059bda0c 100644 (file)
import javax.inject.Inject
@GameScope
+@UseItemAction(UseBedAction.ACTION_KEY)
class UseBedAction @Inject constructor(
private val gameWorld: GameWorld,
private val mobsController: MobsController,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseEmptyBucketAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseEmptyBucketAction.kt
index 57ca3f755305a5531b9cf972078d67e7cbcb6b48..fd64751e64f751bf24ed050cae6ae568561fe976 100644 (file)
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
--- /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
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseLavaBucketAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseLavaBucketAction.kt
index 965961711ee2ec08b44bf07961d8124322be7ea5..70438e3ac8406252b2ff120fb0577effdb06ea21 100644 (file)
import javax.inject.Inject
@GameScope
+@UseItemAction(UseLavaBucketAction.ACTION_KEY)
class UseLavaBucketAction @Inject constructor(
private val gameWorld: GameWorld,
private val mobsController: MobsController,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UsePigSpawnEggAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UsePigSpawnEggAction.kt
index 6c0c3ba714b098fca8390fc85649a91733d71cb4..4b2aa00406d93b5e332509031f50d7b17ae6d571 100644 (file)
import javax.inject.Inject
@GameScope
+@UseItemAction(UsePigSpawnEggAction.ACTION_KEY)
class UsePigSpawnEggAction @Inject constructor(
private val mobsController: MobsController,
private val gameItemsHolder: GameItemsHolder,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseWaterBucketAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseWaterBucketAction.kt
index 15e08fc77bd78962ec8fd6ccfd389a917cd66699..83b8f24f3670df9fbd05041fb5f5e0160831b6ed 100644 (file)
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
--- /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
--- /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
--- /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
diff --git a/dagger-multibind-ksp/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/dagger-multibind-ksp/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
index 293ff25c19743b14299ead59c0db362d3d91d96e..b646e9dcaf2d243a397c87fedcd7b4b2f4e64c2e 100644 (file)
ru.fredboy.cavedroid.ksp.provider.GenerateSetMultibindingsSymbolProcessorProvider
+ru.fredboy.cavedroid.ksp.provider.GenerateMapMultibindingsSymbolProcessorProvider