working crafting workbench

This commit is contained in:
minjaesong
2023-09-20 16:01:40 +09:00
parent a168db23de
commit 5957f70ff8
12 changed files with 145 additions and 31 deletions

View File

@@ -0,0 +1,10 @@
package net.torvald.terrarum.modulebasegame.gameactors
/**
* Created by minjaesong on 2023-09-20.
*/
open interface CraftingStation {
val tags: List<String>
}

View File

@@ -21,7 +21,7 @@ class FixtureWallCalendar : FixtureBase {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/calendar.tga")
density = 600.0
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 1)
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, 0)
makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE, TILE_SIZE)).let {
it.setRowsAndFrames(1,1)

View File

@@ -0,0 +1,35 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.ui.UIWallCalendar
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2023-09-20.
*/
class FixtureWorkbench : FixtureBase, CraftingStation {
@Transient override val tags = listOf("basiccrafting")
constructor() : super(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 1),
nameFun = { Lang["ITEM_WORKBENCH"] },
mainUI = UIWallCalendar()
) {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/workbench.tga")
density = BlockCodex[Block.PLANK_NORMAL].density.toDouble()
setHitboxDimension(itemImage.texture.width, itemImage.texture.height, 0, 0)
makeNewSprite(TextureRegionPack(itemImage.texture, itemImage.texture.width, itemImage.texture.height)).let {
it.setRowsAndFrames(1,1)
}
actorValue[AVKey.BASEMASS] = 20.0
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.App
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.WireCodex
/**
@@ -72,13 +73,20 @@ object PlayerBuilderSigrid {
fun fillTestInventory(inventory: ActorInventory) {
App.tileMaker.tags.forEach { t, _ ->
inventory.add(t, 9995)
try {
inventory.add("wall@$t", 9995) // this code will try to add nonexisting wall items, do not get surprised with NPEs
}
catch (e: Throwable) {
System.err.println("[PlayerBuilder] $e")
App.tileMaker.tags.forEach { (t, _) ->
if (!BlockCodex[t].isActorBlock) {
inventory.add(t, 9995)
try {
inventory.add(
"wall@$t",
9995
) // this code will try to add nonexisting wall items, do not get surprised with NPEs
}
catch (e: NullPointerException) { /* tHiS iS fInE */ }
catch (e: Throwable) {
System.err.println("[PlayerBuilder] $e")
}
}
}
@@ -100,6 +108,8 @@ object PlayerBuilderSigrid {
inventory.add("item@basegame:11", 10) // calendar
inventory.add("item@basegame:16", 10) // workbench
// inventory.add("item@basegame:256", 995) // doors
// inventory.add("item@basegame:257", 995) // doors
// inventory.add("item@basegame:258", 995) // doors

View File

@@ -0,0 +1,29 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.gameitems.ItemID
/**
* Created by minjaesong on 2023-09-20.
*/
class ItemWorkbench(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureWorkbench") {
override val originalName = "ITEM_WORKBENCH"
override var baseMass = 20.0
override var stackable = true
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val materialId = ""
override val itemImage: TextureRegion
get() = getItemImageFromSingleImage("basegame", "sprites/fixtures/workbench.tga")
override var baseToolSize: Double? = baseMass
init {
equipPosition = EquipPosition.HAND_GRIP
}
}

View File

@@ -4,8 +4,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.App.gamepadLabelLEFTRIGHT
import net.torvald.terrarum.App.gamepadLabelStart
import net.torvald.terrarum.App.*
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem
@@ -13,6 +12,7 @@ import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isWall
import net.torvald.terrarum.itemproperties.CraftingCodex
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.CraftingStation
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
@@ -121,7 +121,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
// list of [Score, Ingredients, Recipe]
recipes.map { recipe ->
// list of (Item, How many player has, How many the recipe requires)
val items = recipeToIngredientRecord(player, recipe, listOf(/*todo: nearby crafting stations*/))
val items = recipeToIngredientRecord(player, recipe, nearbyCraftingStations)
val score = items.fold(1L) { acc, item ->
(item.howManyPlayerHas).times(16L) + 1L
@@ -330,6 +330,16 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
addUIitem(buttonCraft)
}
var nearbyCraftingStations = emptyList<String>(); protected set
fun getCraftingStationsWithinReach(): List<String> {
val reach = INGAME.actorNowPlaying!!.actorValue.getAsDouble(AVKey.REACH)!! * (INGAME.actorNowPlaying!!.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * INGAME.actorNowPlaying!!.scale
val nearbyCraftingStations = INGAME.findKNearestActors(INGAME.actorNowPlaying!!, 256) {
it is CraftingStation && (distBetweenActors(it, INGAME.actorNowPlaying!!) < reach)
}
return nearbyCraftingStations.flatMap { (it.get() as CraftingStation).tags }
}
private fun changeIngredient(old: InventoryPair, new: ItemID) {
itemListPlayer.removeFromForceHighlightList(oldSelectedItems)
@@ -391,6 +401,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
private var openingClickLatched = false
override fun show() {
nearbyCraftingStations = getCraftingStationsWithinReach()
// printdbg(this, "Nearby crafting stations: $nearbyCraftingStations")
itemListPlayer.getInventory = { INGAME.actorNowPlaying!!.inventory }
itemListUpdate()

View File

@@ -74,8 +74,7 @@ class UIItemCraftingCandidateGrid(
craftingRecipes.clear()
CraftingRecipeCodex.props.forEach { (_, recipes) ->
recipes.forEach {
// TODO check for nearby crafting stations
if (isCraftable((parentUI as UICrafting).getPlayerInventory(), it, listOf(/*todo: nearby crafting stations*/))) craftingRecipes.add(it)
if (isCraftable((parentUI as UICrafting).getPlayerInventory(), it, (parentUI as UICrafting).nearbyCraftingStations)) craftingRecipes.add(it)
}
}