* Suppression de la mutation éphémère * Ajout des modificateur de régions normaux Sableux et Toxique * Ajout de modificateurs challenge (Rocheux, Radioactif et Contaminé) * Ajout du modificateur de région bénéfique Résonnance * Ajout d'un distributeur toutes les 3 régions * Ajout des régions challenge * Bouclage sur les couleurs des mutations après le niveau 4 * Ajout de deux nouveaux panneaux de tutoriel, un sur les informations de plantes et l'autre sur le vaisseau
144 lines
3.4 KiB
GDScript
144 lines
3.4 KiB
GDScript
@tool
|
|
extends Resource
|
|
class_name Inventory
|
|
|
|
signal updated(inventory: Inventory)
|
|
signal tool_added(item: Item)
|
|
|
|
@export var tools: Array[Item] = []
|
|
@export var seeds: Array[Item] = []
|
|
@export var current_item_ind: int = 0 # over both tools and items
|
|
@export var seeds_size : int :
|
|
set(v):
|
|
seeds_size = v
|
|
update_seeds_size(v)
|
|
|
|
func _init(size : int = 1):
|
|
seeds_size = size
|
|
|
|
func current_is_tool() -> bool:
|
|
return current_item_ind <= len(tools)
|
|
|
|
func set_current_item(new_ind: int):
|
|
if new_ind != current_item_ind:
|
|
current_item_ind = new_ind % (len(tools) + len(seeds))
|
|
updated.emit(self)
|
|
|
|
func change_current_item(ind_mod: int):
|
|
set_current_item(current_item_ind + ind_mod)
|
|
|
|
func add_item(item: Item) -> bool:
|
|
if item.type != Item.ItemType.TOOL_ITEM:
|
|
return add_seed(item)
|
|
elif item.type == Item.ItemType.TOOL_ITEM and not has_item_with_name(item.get_item_name()):
|
|
add_tool(item)
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
func add_tool(tool: Item) -> bool:
|
|
if not has_item_with_name(tool.get_item_name()):
|
|
tools.append(tool)
|
|
current_item_ind += 1
|
|
updated.emit(self)
|
|
tool_added.emit(tool)
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
func add_seed(s: Item) -> bool:
|
|
update_seeds_size()
|
|
if not is_full():
|
|
var ind = (
|
|
current_item_ind - len(tools) if current_item_ind > len(tools)
|
|
else 0
|
|
)
|
|
|
|
while seeds[ind] != null:
|
|
ind = (ind+1) % len(seeds)
|
|
|
|
seeds[ind] = s
|
|
|
|
updated.emit(self)
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
func update_seeds_size(size = seeds_size):
|
|
while size > len(seeds):
|
|
seeds.append(null)
|
|
|
|
while len(seeds) > size and seeds.find(null) != -1:
|
|
seeds.pop_at(seeds.find(null))
|
|
|
|
func get_all_items() -> Array[Item]:
|
|
return tools + seeds
|
|
|
|
func get_item(ind: int = current_item_ind) -> Item:
|
|
if ind < 0 || ind > len(get_all_items()):
|
|
return null
|
|
return get_all_items()[ind]
|
|
|
|
func has_item(item: Item) -> bool:
|
|
return get_all_items().has(item)
|
|
|
|
func has_item_with_name(name: String) -> bool:
|
|
var id = get_all_items().find_custom(
|
|
(func (i : Item):
|
|
return i and i.get_item_name() == name)
|
|
)
|
|
return id != -1
|
|
|
|
func remove_tool(ind : int):
|
|
if ind != -1:
|
|
tools.pop_at(ind)
|
|
updated.emit(self)
|
|
|
|
func remove_seed(ind : int):
|
|
if ind != -1:
|
|
seeds[ind] = null
|
|
updated.emit(self)
|
|
update_seeds_size(seeds_size)
|
|
|
|
func remove_item(item: Item) -> bool:
|
|
if tools.find(item) != -1:
|
|
remove_tool(tools.find(item))
|
|
elif seeds.find(item) != -1:
|
|
remove_seed(seeds.find(item))
|
|
else:
|
|
return false
|
|
return true
|
|
|
|
func remove_item_at(ind: int = current_item_ind) -> bool:
|
|
if ind < 0 || ind > len(seeds) + len(tools):
|
|
return false
|
|
|
|
if ind < len(tools):
|
|
remove_tool(ind)
|
|
else:
|
|
remove_seed(ind - len(tools))
|
|
|
|
return true
|
|
|
|
func remove_current_item():
|
|
remove_item_at()
|
|
|
|
func pop_item(ind: int = current_item_ind) -> Item:
|
|
if ind < 0 || ind > len(seeds) + len(tools):
|
|
return null
|
|
|
|
var item_removed = get_item(ind)
|
|
|
|
remove_item_at(ind)
|
|
|
|
return item_removed
|
|
|
|
func is_full():
|
|
for i in range(len(seeds)):
|
|
if seeds[i] == null:
|
|
return false
|
|
return true
|
|
|
|
func current_ind_on_tools() -> bool:
|
|
return current_item_ind < len(tools)
|