97 lines
2.3 KiB
GDScript
97 lines
2.3 KiB
GDScript
extends Window
|
|
|
|
@onready var inventoryDisplayer = %InventoryDisplayer
|
|
|
|
var itemPlanted = null
|
|
|
|
func _ready():
|
|
inventoryDisplayer.buttonPressed.connect(add_ash)
|
|
|
|
func opened():
|
|
get_tree().paused = true
|
|
reset_display()
|
|
|
|
func _process(delta):
|
|
if visible:
|
|
update_time_to_growth()
|
|
|
|
func reset_display():
|
|
itemPlanted = get_parent().currentItem
|
|
|
|
%ItemSprite.texture = itemPlanted.get_sprite()
|
|
%PlantedItemName.text = itemPlanted.get_name()
|
|
|
|
update_harvest_lives()
|
|
update_time_to_growth()
|
|
|
|
initialize_inventory()
|
|
|
|
func add_ash(ashItem):
|
|
InventoryManager.remove_item_from_inventory(ashItem)
|
|
|
|
var bonusLives = get_bonus_lives(ashItem)
|
|
if bonusLives > 0:
|
|
get_parent().add_plant_lives(bonusLives)
|
|
update_harvest_lives()
|
|
|
|
var timeBoost = get_time_boost(ashItem)
|
|
get_parent().add_time_boosted(timeBoost)
|
|
|
|
update_inventory()
|
|
|
|
func update_harvest_lives():
|
|
%HarvestBoost.text = "Harvest Boost: " + str(get_parent().plantLives) + "x"
|
|
|
|
func update_time_to_growth():
|
|
var timeToGrowth = floor(get_parent().get_time_to_next_state_change())
|
|
|
|
var timeString = TimeDisplayUtils.get_time_string(timeToGrowth)
|
|
%GrowthTime.text = "Growth Time:\n" + timeString
|
|
|
|
func get_time_boost(ashItem):
|
|
var timeBoost = 10
|
|
timeBoost += ashItem.get_edibility() * 1.2
|
|
timeBoost = ceil(timeBoost)
|
|
|
|
if timeBoost < 0:
|
|
timeBoost = 0
|
|
|
|
return timeBoost
|
|
|
|
func get_bonus_lives(ashItem):
|
|
var bonusLives = 0
|
|
var ashName = ashItem.get_name(false)
|
|
ashName = ashName.substr(0, ashName.length() - 4)
|
|
|
|
if ashName in itemPlanted.get_name(false):
|
|
bonusLives = 1
|
|
|
|
return bonusLives
|
|
|
|
func initialize_inventory():
|
|
var playerInventory = InventoryManager.get_inventory()
|
|
inventoryDisplayer.inventory = filter_inventory(playerInventory)
|
|
inventoryDisplayer.update_display()
|
|
inventoryDisplayer.set_title("Ash Items")
|
|
|
|
func update_inventory():
|
|
var playerInventory = InventoryManager.get_inventory()
|
|
inventoryDisplayer.inventory = filter_inventory(playerInventory)
|
|
inventoryDisplayer.update_display()
|
|
|
|
func filter_inventory(inventory):
|
|
var filteredInv:Inventory = Inventory.new()
|
|
|
|
var i = inventory.items.size() - 1
|
|
while i >= 0:
|
|
var currentItem = inventory.items[i]
|
|
if Item.types.Ash in currentItem.itemTypes:
|
|
filteredInv.add_item(currentItem.duplicate(), inventory.quantities[i])
|
|
i -= 1
|
|
|
|
return filteredInv
|
|
|
|
func _on_leave_button_pressed():
|
|
get_tree().paused = false
|
|
hide()
|