X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FGameInput.java;h=fb20d8fb0520ff9fe125d29ce1de5a4645f1161c;hb=289536374d18bb05cde615c04d9fe576d6ac26bc;hp=fd225742fadbe16affe54246965bb40c9cff9e0d;hpb=476b65903ad1082a1847eb2a8076ab1039358790;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index fd22574..fb20d8f 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -26,8 +26,6 @@ import javax.inject.Inject; import java.util.Map; -import static ru.deadsoftware.cavedroid.game.GameItems.*; - @GameScope public class GameInput { @@ -37,6 +35,7 @@ public class GameInput { private final GameWorld mGameWorld; private final DropController mDropController; private final MobsController mMobsController; + private final GameItemsHolder mGameItemsHolder; private final Map mUseItemActionMap; private final Map mPlaceBlockActionMap; @@ -64,12 +63,14 @@ public class GameInput { GameWorld gameWorld, DropController dropController, MobsController mobsController, + GameItemsHolder gameItemsHolder, Map useItemActionMap, Map placeBlockActionMap) { mMainConfig = mainConfig; mGameWorld = gameWorld; mDropController = dropController; mMobsController = mobsController; + mGameItemsHolder = gameItemsHolder; mUseItemActionMap = useItemActionMap; mPlaceBlockActionMap = placeBlockActionMap; @@ -79,7 +80,7 @@ public class GameInput { } private boolean checkSwim() { - return GameItems.isFluid(mGameWorld.getForeMap(mPlayer.getMapX(), mPlayer.getLowerMapY())); + return mGameWorld.getForeMap(mPlayer.getMapX(), mPlayer.getLowerMapY()).isFluid(); } private void goUpwards() { @@ -150,7 +151,7 @@ public class GameInput { } private boolean isNotAutoselectable(int x, int y) { - return (!mGameWorld.hasForeAt(x, y) || !mGameWorld.getForeMapBlock(x, y).hasCollision()); + return (!mGameWorld.hasForeAt(x, y) || !mGameWorld.getForeMap(x, y).hasCollision()); } private void checkCursorBounds() { @@ -208,27 +209,27 @@ public class GameInput { checkCursorBounds(); } - private void useItem(int x, int y, int id, boolean bg) { + private void useItem(int x, int y, @CheckForNull Item item, boolean bg) { mPlayer.startHitting(); - if (id > 0) { - final Item item = getItem(id); + if (item == null) { + return; + } - if (item instanceof Item.Placeable) { - if (!bg) { - CommonBlockActionUtilsKt.placeToForegroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y); - } else { - CommonBlockActionUtilsKt.placeToBackgroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y); - } - } else if (item instanceof Item.Usable) { - final String actionKey = ((Item.Usable)item).getUseActionKey(); - final IUseItemAction useItemAction = mUseItemActionMap.get(actionKey); + if (item instanceof Item.Placeable) { + if (!bg) { + CommonBlockActionUtilsKt.placeToForegroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y); + } else { + CommonBlockActionUtilsKt.placeToBackgroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y); + } + } else if (item instanceof Item.Usable) { + final String actionKey = ((Item.Usable) item).getUseActionKey(); + final IUseItemAction useItemAction = mUseItemActionMap.get(actionKey); - if (useItemAction != null) { - useItemAction.perform((Item.Usable) item, x, y); - } else { - Gdx.app.error(TAG, "use item action " + actionKey + " not found"); - } + if (useItemAction != null) { + useItemAction.perform((Item.Usable) item, x, y); + } else { + Gdx.app.error(TAG, "use item action " + actionKey + " not found"); } } } @@ -247,27 +248,27 @@ public class GameInput { if (mMainConfig.checkGameUiWindow(GameUiWindow.NONE)) { mPlayer.startHitting(); - if ((mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.getForeMapBlock(mCurX, mCurY).getHp() >= 0) || + if ((mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.getForeMap(mCurX, mCurY).getHp() >= 0) || (!mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.hasBackAt(mCurX, mCurY) && - mGameWorld.getBackMapBlock(mCurX, mCurY).getHp() >= 0)) { + mGameWorld.getBackMap(mCurX, mCurY).getHp() >= 0)) { if (mPlayer.gameMode == 0) { mBlockDamage++; if (mGameWorld.hasForeAt(mCurX, mCurY)) { - if (mBlockDamage >= mGameWorld.getForeMapBlock(mCurX, mCurY).getHp()) { + if (mBlockDamage >= mGameWorld.getForeMap(mCurX, mCurY).getHp()) { mGameWorld.destroyForeMap(mCurX, mCurY); mBlockDamage = 0; } } else if (mGameWorld.hasBackAt(mCurX, mCurY)) { - if (mBlockDamage >= mGameWorld.getBackMapBlock(mCurX, mCurY).getHp()) { + if (mBlockDamage >= mGameWorld.getBackMap(mCurX, mCurY).getHp()) { mGameWorld.destroyBackMap(mCurX, mCurY); mBlockDamage = 0; } } } else { if (mGameWorld.hasForeAt(mCurX, mCurY)) { - mGameWorld.placeToForeground(mCurX, mCurY, 0); + mGameWorld.placeToForeground(mCurX, mCurY, mGameItemsHolder.getFallbackBlock()); } else if (mGameWorld.hasBackAt(mCurX, mCurY)) { - mGameWorld.placeToBackground(mCurX, mCurY, 0); + mGameWorld.placeToBackground(mCurX, mCurY, mGameItemsHolder.getFallbackBlock()); } mTouchedDown = false; } @@ -287,7 +288,7 @@ public class GameInput { private void holdMB() { if (mTouchDownBtn == Input.Buttons.RIGHT) { - useItem(mCurX, mCurY, mPlayer.inventory[mPlayer.slot], true); + useItem(mCurX, mCurY, mPlayer.inventory[mPlayer.slot].getItem(), true); mTouchedDown = false; } else { if (insideHotbar(mTouchDownX, mTouchDownY)) { @@ -332,11 +333,8 @@ public class GameInput { break; case Input.Keys.G: - mMobsController.addMob(new Pig(mCurX * 16, mCurY * 16)); - break; - - case Input.Keys.Q: - mGameWorld.placeToForeground(mCurX, mCurY, 8); + final Mob pig = new Pig(mCurX * 16, mCurY * 16); + pig.attachToController(mMobsController); break; case Input.Keys.GRAVE: @@ -407,14 +405,13 @@ public class GameInput { if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY) && insideCreativeInv(screenX, screenY)) { int ix = (int) (screenX - (mMainConfig.getWidth() / 2 - creative.getRegionWidth() / 2 + 8)) / 18; int iy = (int) (screenY - (mMainConfig.getHeight() / 2 - creative.getRegionHeight() / 2 + 18)) / 18; - int item = mCreativeScroll * 8 + (ix + iy * 8); + int itemPos = mCreativeScroll * 8 + (ix + iy * 8); if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) { - item = -1; - } - if (item >= 0 && item < GameItems.getItemsSize()) { - System.arraycopy(mPlayer.inventory, 0, mPlayer.inventory, 1, 8); - mPlayer.inventory[0] = item; + itemPos = -1; } + + System.arraycopy(mPlayer.inventory, 0, mPlayer.inventory, 1, 8); + mPlayer.inventory[0] = mGameItemsHolder.getItemFromCreativeInventory(itemPos).toInventoryItem(); } else if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY)) { mMainConfig.setGameUiWindow(GameUiWindow.NONE); } else if (screenY < hotbar.getRegionHeight() && @@ -423,7 +420,7 @@ public class GameInput { mPlayer.slot = (int) ((screenX - (mMainConfig.getWidth() / 2 - hotbar.getRegionWidth() / 2)) / 20); } else if (button == Input.Buttons.RIGHT) { useItem(mCurX, mCurY, - mPlayer.inventory[mPlayer.slot], false); + mPlayer.inventory[mPlayer.slot].getItem(), false); } else if (button == Input.Buttons.LEFT) { mBlockDamage = 0; } @@ -445,8 +442,10 @@ public class GameInput { if (mCreativeScroll < 0) { mCreativeScroll = 0; } - if (mCreativeScroll > GameProc.MAX_CREATIVE_SCROLL) { - mCreativeScroll = GameProc.MAX_CREATIVE_SCROLL; + + final int maxScroll = mGameItemsHolder.getCreativeScrollAmount(); + if (mCreativeScroll > maxScroll) { + mCreativeScroll = maxScroll; } } } @@ -468,8 +467,10 @@ public class GameInput { if (mCreativeScroll < 0) { mCreativeScroll = 0; } - if (mCreativeScroll > GameProc.MAX_CREATIVE_SCROLL) { - mCreativeScroll = GameProc.MAX_CREATIVE_SCROLL; + + final int maxScroll = mGameItemsHolder.getCreativeScrollAmount(); + if (mCreativeScroll > maxScroll) { + mCreativeScroll = maxScroll; } break; }