~interfiber/Lambda

[PATCH] Plant crops & save crop data in the world save file

Details
Message ID
<bb3fda80-d214-84a4-9702-c312cb50e50f@interfiber.dev>
DKIM signature
missing
Download raw message
This is a real patch, also just testing patches to make sure they work

 From e398f17da86b623587efb19de52030facfcd4373 Mon Sep 17 00:00:00 2001
From: Interfiber <webmaster@interfiber.dev>
Date: Thu, 28 Jul 2022 20:21:57 -0400
Subject: [PATCH] plant crops, and save the crops in save files

---
  assets/wheat.png                              | Bin 0 -> 248 bytes
  assets/wheat_seeds_item.png                   | Bin 0 -> 152 bytes
  core/src/com/interfiber/lambda/Assets.java    |   4 ++
  .../lambda/bootstrap/GameBootstrap.java       |   3 --
  .../lambda/farming/CropManager.java           |   9 +++-
  .../com/interfiber/lambda/items/ItemType.java |   4 +-
  .../interfiber/lambda/items/ItemUtils.java    |   4 ++
  .../interfiber/lambda/items/WheatItem.java    |  36 +++++++++++++++
  .../lambda/items/WheatSeedsItem.java          |  43 ++++++++++++++++++
  .../lambda/overlays/PauseMenuOverlay.java     |   2 +-
  .../lambda/screens/NewWorldScreen.java        |   2 +-
  .../lambda/weather/ThunderstormWeather.java   |   2 +-
  .../com/interfiber/lambda/world/GameSave.java |   2 +-
  .../interfiber/lambda/world/WorldSaver.java   |   4 ++
  14 files changed, 106 insertions(+), 9 deletions(-)
  create mode 100644 assets/wheat.png
  create mode 100644 assets/wheat_seeds_item.png
  create mode 100644 core/src/com/interfiber/lambda/items/WheatItem.java
  create mode 100644 
core/src/com/interfiber/lambda/items/WheatSeedsItem.java

diff --git a/assets/wheat.png b/assets/wheat.png
new file mode 100644
index 
0000000000000000000000000000000000000000..894b831530bb917390530911576404e67ca6da78
GIT binary patch
literal 248
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}n><|{Ln2y}
z6C_v{Cy4Zv9PscsIQ6#P|HK^GtF|mxgRe54n0EP;pat*YG)rBXgD$$wFJ3X!EOZuU
z54bF-qV6Q2@nP?Y13<9h`LXP-OU#}(1#Tuu%-9e)f02u)0oMdx_w6!l8l8NLV&5%N
z<l3HcD6Mu))(K9|RcVK{x5xgQEG4CLMC(rRV^d|*&GI}GWKvpW9J5R&Osy)kY?@=@
tQ1;ESoJBXwYm<x-m)k)N3DzY{3{H2QFZD`x!~k8-;OXk;vd$@?2>?bYS_%LF

literal 0
HcmV?d00001

diff --git a/assets/wheat_seeds_item.png b/assets/wheat_seeds_item.png
new file mode 100644
index 
0000000000000000000000000000000000000000..0153e14ab8e7d21b417833e5e85e5928ffd77915
GIT binary patch
literal 152
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}L7py-ArY;~
z2@<Rs4^HJy|KEIb&q2nv<?AmTJn=!*mNC|;<VS?j6UI=d&UKEqNsmf@RF?esnGwKL
x)Ldy&<;JLJFw1QNQ_Vpqp9#HeuQe3d85r*HnX)p<Uk2ID;OXk;vd$@?2>|H^GS>hA

literal 0
HcmV?d00001

diff --git a/core/src/com/interfiber/lambda/Assets.java 
b/core/src/com/interfiber/lambda/Assets.java
index b860b66..251d362 100644
--- a/core/src/com/interfiber/lambda/Assets.java
+++ b/core/src/com/interfiber/lambda/Assets.java
@@ -53,6 +53,8 @@ public class Assets {
      public static final String FARMLAND_TEXTURE = "farmland.png";
      public static final String WOOD_HOE_ITEM_TEXTURE = 
"wood_hoe_item.png";
      public static final String WHEAT_SEEDS_TEXTURE = "wheat_seeds.png";
+    public static final String WHEAT_TEXTURE = "wheat.png";
+    public static final String WHEAT_SEEDS_ITEM_TEXTURE = 
"wheat_seeds_item.png";

      public static void loadAssets() {
          Logger.info("Loading game assets");
@@ -90,6 +92,8 @@ public class Assets {
          manager.load(FARMLAND_TEXTURE, Texture.class);
          manager.load(WOOD_HOE_ITEM_TEXTURE, Texture.class);
          manager.load(WHEAT_SEEDS_TEXTURE, Texture.class);
+        manager.load(WHEAT_TEXTURE, Texture.class);
+        manager.load(WHEAT_SEEDS_ITEM_TEXTURE, Texture.class);

          // audio or music
          manager.load(CLICK_3_AUDIO, Sound.class);
diff --git a/core/src/com/interfiber/lambda/bootstrap/GameBootstrap.java 
b/core/src/com/interfiber/lambda/bootstrap/GameBootstrap.java
index a4d2b9c..08b30e1 100644
--- a/core/src/com/interfiber/lambda/bootstrap/GameBootstrap.java
+++ b/core/src/com/interfiber/lambda/bootstrap/GameBootstrap.java
@@ -3,9 +3,6 @@ import com.interfiber.lambda.Game;
  import com.interfiber.lambda.controllers.*;
  import com.interfiber.lambda.crafting.RecipeManager;
  import com.interfiber.lambda.crafting.recipes.*;
-import com.interfiber.lambda.farming.CropManager;
-import com.interfiber.lambda.farming.CropType;
-import com.interfiber.lambda.farming.crops.WheatCrop;
  import com.interfiber.lambda.misc.AutoGCService;
  import com.interfiber.lambda.options.GameOptions;
  import com.interfiber.lambda.options.OptionManager;
diff --git a/core/src/com/interfiber/lambda/farming/CropManager.java 
b/core/src/com/interfiber/lambda/farming/CropManager.java
index 3d8dcda..eee5628 100644
--- a/core/src/com/interfiber/lambda/farming/CropManager.java
+++ b/core/src/com/interfiber/lambda/farming/CropManager.java
@@ -1,7 +1,9 @@
  package com.interfiber.lambda.farming;

  import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.interfiber.lambda.Game;
  import com.interfiber.lambda.farming.crops.WheatCrop;
+import com.interfiber.lambda.tiles.TileType;
  import java.util.ArrayList;
  import org.tinylog.Logger;

@@ -27,6 +29,12 @@ public class CropManager {
      }

      public static void plantCrop(CropType cropType, int x, int y) {
+        if (Game.getCurrentWorld().getTileAtPosition(x, y) != null) {
+            if (Game.getCurrentWorld().getTileAtPosition(x, y).type != 
TileType.FARMLAND) {
+                Game.alertSystem.createToast("You can only place crops 
on tilled soil!");
+                return;
+            }
+        }
          if (getCropAtPosition(x, y) != null) {
              Logger.warn("Crop is already at that position");
              return;
@@ -34,7 +42,6 @@ public class CropManager {
              Crop crop = cropTypeToCrop(cropType);
              crop.plant();
              plantedCrops.add(crop.getSerializableCrop(x, y));
-            Logger.info("Planted crop");
          }
      }

diff --git a/core/src/com/interfiber/lambda/items/ItemType.java 
b/core/src/com/interfiber/lambda/items/ItemType.java
index 014f2a2..97b483a 100644
--- a/core/src/com/interfiber/lambda/items/ItemType.java
+++ b/core/src/com/interfiber/lambda/items/ItemType.java
@@ -15,5 +15,7 @@ public enum ItemType {
      IRON_ORE,
      IRON_PICKAXE,
      CHEST,
-    WOOD_HOE
+    WOOD_HOE,
+    WHEAT,
+    WHEAT_SEEDS
  }
diff --git a/core/src/com/interfiber/lambda/items/ItemUtils.java 
b/core/src/com/interfiber/lambda/items/ItemUtils.java
index 01f8676..91c7755 100644
--- a/core/src/com/interfiber/lambda/items/ItemUtils.java
+++ b/core/src/com/interfiber/lambda/items/ItemUtils.java
@@ -33,6 +33,10 @@ public class ItemUtils {
                  return new ChestItem();
              case WOOD_HOE:
                  return new WoodHoeItem();
+            case WHEAT:
+                return new WheatItem();
+            case WHEAT_SEEDS:
+                return new WheatSeedsItem();
          }
          return null;
      }
diff --git a/core/src/com/interfiber/lambda/items/WheatItem.java 
b/core/src/com/interfiber/lambda/items/WheatItem.java
new file mode 100644
index 0000000..3ebb9bc
--- /dev/null
+++ b/core/src/com/interfiber/lambda/items/WheatItem.java
@@ -0,0 +1,36 @@
+package com.interfiber.lambda.items;
+
+import com.badlogic.gdx.graphics.Texture;
+import com.interfiber.lambda.Assets;
+import com.interfiber.lambda.player.Player;
+import com.interfiber.lambda.tiles.TileType;
+
+public class WheatItem extends Item {
+
+    @Override
+    public Texture getTextureName() {
+        return Assets.manager.get("wheat.png");
+    }
+
+    @Override
+    public String getItemDisplayName() {
+        return "Wheat";
+    }
+
+    @Override
+    public ItemType getType() {
+        return ItemType.WHEAT;
+    }
+
+    @Override
+    public void interact(int slot) {
+        Player.inventoryTile = TileType.ITEM;
+    }
+
+    @Override
+    public void removed(boolean finalRemove) {
+        if (finalRemove) {
+            Player.inventoryTile = TileType.AIR;
+        }
+    }
+}
diff --git a/core/src/com/interfiber/lambda/items/WheatSeedsItem.java 
b/core/src/com/interfiber/lambda/items/WheatSeedsItem.java
new file mode 100644
index 0000000..3be0d54
--- /dev/null
+++ b/core/src/com/interfiber/lambda/items/WheatSeedsItem.java
@@ -0,0 +1,43 @@
+package com.interfiber.lambda.items;
+
+import com.badlogic.gdx.graphics.Texture;
+import com.interfiber.lambda.Assets;
+import com.interfiber.lambda.tiles.TileType;
+import com.interfiber.lambda.player.Player;
+import com.interfiber.lambda.world.WorldTile;
+import com.interfiber.lambda.farming.*;
+
+public class WheatSeedsItem extends Item {
+
+    @Override
+    public Texture getTextureName() {
+        return Assets.manager.get("wheat_seeds_item.png");
+    }
+
+    @Override
+    public String getItemDisplayName() {
+        return "Wheat Seeds";
+    }
+
+    @Override
+    public ItemType getType() {
+        return ItemType.WHEAT_SEEDS;
+    }
+
+    @Override
+    public void interact(int slot) {
+        Player.inventoryTile = TileType.ITEM;
+    }
+
+    @Override
+    public void removed(boolean finalRemove) {
+        if (finalRemove) {
+            Player.inventoryTile = TileType.AIR;
+        }
+    }
+
+    @Override
+    public void tileClicked(WorldTile tile) {
+        CropManager.plantCrop(CropType.WHEAT, tile.x, tile.y);
+    }
+}
diff --git 
a/core/src/com/interfiber/lambda/overlays/PauseMenuOverlay.java 
b/core/src/com/interfiber/lambda/overlays/PauseMenuOverlay.java
index 206e5d2..67813af 100644
--- a/core/src/com/interfiber/lambda/overlays/PauseMenuOverlay.java
+++ b/core/src/com/interfiber/lambda/overlays/PauseMenuOverlay.java
@@ -30,7 +30,7 @@ public class PauseMenuOverlay extends Overlay {
              if (tick != 0) {
                  tick += 1;
              }
-            if (tick == 125) {
+            if (tick == 5) {
                  try {
                      WorldSaver.runSave(Game.currentSaveFile);
                  } catch (IOException e) {
diff --git a/core/src/com/interfiber/lambda/screens/NewWorldScreen.java 
b/core/src/com/interfiber/lambda/screens/NewWorldScreen.java
index a1d5803..fd13dc1 100644
--- a/core/src/com/interfiber/lambda/screens/NewWorldScreen.java
+++ b/core/src/com/interfiber/lambda/screens/NewWorldScreen.java
@@ -51,7 +51,7 @@ public class NewWorldScreen extends ScreenAdapter {
          if (tick != 0) {
              tick += 1;
          }
-        if (tick > 120) {
+        if (tick > 5) {
              tick = 0;
              // create world
              Logger.info("Creating world");
diff --git 
a/core/src/com/interfiber/lambda/weather/ThunderstormWeather.java 
b/core/src/com/interfiber/lambda/weather/ThunderstormWeather.java
index 95cf2bd..40355a1 100644
--- a/core/src/com/interfiber/lambda/weather/ThunderstormWeather.java
+++ b/core/src/com/interfiber/lambda/weather/ThunderstormWeather.java
@@ -23,7 +23,7 @@ public class ThunderstormWeather extends Weather {

      @Override
      public void renderWeather(SpriteBatch batch) {
-        if (Game.currentWorld != WorldType.OVERWORLD) {
+        if (Game.currentWorld != WorldType.OVERWORLD || Game.time != 
Time.NIGHT) {
              Logger.info("Stopping weather, incorrect Game.currentWorld");
              // thunderstorms dont happen underground, duh
              WeatherUtils.setWeather(null);
diff --git a/core/src/com/interfiber/lambda/world/GameSave.java 
b/core/src/com/interfiber/lambda/world/GameSave.java
index cd87153..5e004f9 100644
--- a/core/src/com/interfiber/lambda/world/GameSave.java
+++ b/core/src/com/interfiber/lambda/world/GameSave.java
@@ -22,7 +22,7 @@ public class GameSave implements Serializable {
                                     // data
      public List<WorldTile> overworldData; // overworld terrain data
      public List<WorldTile> underworldData; // underworld terrain data
-    public ArrayList<SerializableCrop> cropData; // crop data
+    public ArrayList<SerializableCrop> cropData = new ArrayList<>(); // 
crop data
      public WorldType currentWorld; // current world

      public int underworldX = 0; // current undreworld position(X)
diff --git a/core/src/com/interfiber/lambda/world/WorldSaver.java 
b/core/src/com/interfiber/lambda/world/WorldSaver.java
index 273b465..8fd642b 100644
--- a/core/src/com/interfiber/lambda/world/WorldSaver.java
+++ b/core/src/com/interfiber/lambda/world/WorldSaver.java
@@ -3,6 +3,7 @@ package com.interfiber.lambda.world;
  import com.badlogic.gdx.Gdx;
  import com.badlogic.gdx.math.Vector2;
  import com.interfiber.lambda.Game;
+import com.interfiber.lambda.farming.CropManager;
  import com.interfiber.lambda.lighting.Time;
  import com.interfiber.lambda.player.Player;
  import com.interfiber.lambda.weather.WeatherType;
@@ -36,6 +37,7 @@ public class WorldSaver {

          save.overworldData = Game.overworld.getWorldData();
          save.underworldData = Game.underworld.getWorldData();
+        save.cropData = CropManager.getCropData();

          save.overworldX = (int) Game.overworldSpawnPoint.x;
          save.overworldY = (int) Game.overworldSpawnPoint.y;
@@ -103,6 +105,8 @@ public class WorldSaver {
              Player.caveEnterX = save.caveEntranceX;
              Player.caveEnterY = save.caveEntranceY;

+            CropManager.loadCropData(save.cropData);
+
              if (save.weather != WeatherType.CLEAR) {
WeatherUtils.setWeather(WeatherUtils.weatherTypeToWeather(save.weather));
              }
-- 
2.37.0
Reply to thread Export thread (mbox)