From: fredboy Date: Tue, 14 May 2024 17:25:11 +0000 (+0700) Subject: Game action modules generation X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=d9211ab755d82ecf9553527a734ab5db38f8fe74;p=cavedroid.git Game action modules generation --- 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 index f2c5a23..0000000 --- a/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 deleted file mode 100644 index 6f0fc0f..0000000 --- a/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 deleted file mode 100644 index 7458dfc..0000000 --- a/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 deleted file mode 100644 index d5e4f4f..0000000 --- a/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 deleted file mode 100644 index 06c70c4..0000000 --- a/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 new file mode 100644 index 0000000..e0f6cd8 --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockAction.kt @@ -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 fdfb61a..0a5399a 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt @@ -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, 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 22aafdd..d3ff979 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt @@ -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, 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 6ac94c9..3e0a185 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt @@ -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, 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 9cc4aea..a397f16 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt @@ -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) 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 15621a2..4e43f8f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt @@ -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, 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 4d47b35..78e81fa 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt @@ -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, 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 d5ca3b1..56f814f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt @@ -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, 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 6cc026f..f51bc7f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt @@ -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, 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 57172a5..6b15a7a 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt @@ -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 { 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 4a2b58e..f2ef25e 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt @@ -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, 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 0aa5c90..049c90b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSnowedGrassAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSnowedGrassAction.kt @@ -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 index ddc70c5..0000000 --- a/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 new file mode 100644 index 0000000..932bbf6 --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseBlockAction.kt @@ -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 fa50c94..fd370db 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseChestAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseChestAction.kt @@ -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, 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 3ce42b9..de1112e 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseCraftingTableAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseCraftingTableAction.kt @@ -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 { 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 7c30402..1426263 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseFurnaceAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useblock/UseFurnaceAction.kt @@ -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 index d963aee..0000000 --- a/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 e0f9964..1aefd67 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt @@ -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, 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 57ca3f7..fd64751 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseEmptyBucketAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseEmptyBucketAction.kt @@ -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 index 0000000..be4d254 --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseItemAction.kt @@ -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 9659617..70438e3 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseLavaBucketAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseLavaBucketAction.kt @@ -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, 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 6c0c3ba..4b2aa00 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UsePigSpawnEggAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UsePigSpawnEggAction.kt @@ -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, 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 15e08fc..83b8f24 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseWaterBucketAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseWaterBucketAction.kt @@ -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 index 0000000..7a5b023 --- /dev/null +++ b/dagger-multibind-annotations/src/main/kotlin/ru.fredboy.cavedroid.ksp.annotations/GenerateMapMultibindingsModule.kt @@ -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 index 0000000..cfaa3a5 --- /dev/null +++ b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/processor/GenerateMapMultibindingsSymbolProcessor.kt @@ -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 + ): 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() + .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 { + 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 index 0000000..49ea948 --- /dev/null +++ b/dagger-multibind-ksp/src/main/kotlin/ru/fredboy/cavedroid/ksp/provider/GenerateMapMultibindingsSymbolProcessorProvider.kt @@ -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 293ff25..b646e9d 100644 --- 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 @@ -1 +1,2 @@ ru.fredboy.cavedroid.ksp.provider.GenerateSetMultibindingsSymbolProcessorProvider +ru.fredboy.cavedroid.ksp.provider.GenerateMapMultibindingsSymbolProcessorProvider