Add sprite selection and weapon viewer to weapon creation plugin

This commit is contained in:
MaddoScientisto 2026-02-08 14:58:58 +01:00
commit 04cb3da0cd
8 changed files with 327 additions and 10 deletions

View file

@ -12,6 +12,9 @@ func _enter_tree() -> void:
dock_instance = PanelContainer.new()
dock_instance.set_script(dock_script)
# Pass editor interface to dock
dock_instance.call("setup", get_editor_interface())
# Connect the create button signal from the dock
if dock_instance.has_signal("create_weapon_requested"):
dock_instance.create_weapon_requested.connect(_on_create_weapon_requested)
@ -32,6 +35,7 @@ func _on_create_weapon_requested(weapon_data: Dictionary) -> void:
var ammo_key: String = weapon_data.get("ammo_key", "")
var weapon_short_name: String = weapon_data.get("weapon_short_name", "NW-1")
var weapon_description: String = weapon_data.get("weapon_description", "A new weapon")
var sprite_resource: Texture2D = weapon_data.get("sprite_resource", null)
var default_bullet_path: String = weapon_data.get("default_bullet_path", "res://Resources/Bullets/simple_ice_bullet.tres")
# Weapon stats
@ -70,7 +74,7 @@ func _on_create_weapon_requested(weapon_data: Dictionary) -> void:
# Step 2: Create LootItem resource
if _create_loot_item_resource(item_resource_path, weapon_name, weapon_short_name,
weapon_description, weapon_item_key, weapon_resource_path):
weapon_description, weapon_item_key, weapon_resource_path, sprite_resource):
dock_instance.call("add_log", "✓ Created LootItem at: " + item_resource_path, Color.GREEN)
else:
dock_instance.call("add_log", "✗ Failed to create LootItem", Color.RED)
@ -87,9 +91,8 @@ func _on_create_weapon_requested(weapon_data: Dictionary) -> void:
dock_instance.call("add_log", "=== Weapon Creation Complete ===", Color.CYAN)
dock_instance.call("add_log", "Next steps:")
dock_instance.call("add_log", "1. Add sounds to the weapon resource")
dock_instance.call("add_log", "2. Add a sprite texture to the LootItem")
dock_instance.call("add_log", "3. Test the weapon in-game")
dock_instance.call("add_log", "1. Add sounds to the weapon resource if needed")
dock_instance.call("add_log", "2. Test the weapon in-game")
dock_instance.call("set_creation_complete")
# Refresh the filesystem
@ -151,7 +154,7 @@ func _create_weapon_resource(path: String, weapon_name: String, item_key: String
func _create_loot_item_resource(path: String, item_name: String, short_name: String,
description: String, item_key: String,
weapon_resource_path: String) -> bool:
weapon_resource_path: String, sprite_resource: Texture2D) -> bool:
# Check if file already exists
if ResourceLoader.exists(path):
dock_instance.call("add_log", "Warning: LootItem already exists at " + path, Color.YELLOW)
@ -185,6 +188,12 @@ func _create_loot_item_resource(path: String, item_name: String, short_name: Str
loot_item.set("Selectable", true)
loot_item.set("DropScenePath3D", "res://Scenes/Items/GenericItem3D.tscn")
# Set sprite if provided (supports all Texture2D types including AtlasTexture)
if sprite_resource != null:
loot_item.set("InventorySprite", sprite_resource)
var sprite_type = sprite_resource.get_class()
dock_instance.call("add_log", "✓ Set inventory sprite (" + sprite_type + ")", Color.GREEN)
# Save the resource
var err = ResourceSaver.save(loot_item, path)
if err != OK: