1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00

refactor(资源管理): 集中资源加载逻辑到ComponentManager

将分散在各处的资源加载逻辑统一到ComponentManager中管理
添加对UI组件、主题、物品纹理和饲料的集中管理
移除SkillIconBase.tscn并迁移到UI目录
This commit is contained in:
2025-09-21 13:34:51 +08:00
parent e551a6db61
commit d54c050be9
12 changed files with 37 additions and 15 deletions
+3 -3
View File
@@ -24,9 +24,9 @@ func _ready():
refreshNeedBaseballCount *= 1 + randf_range(GameRule.refreshCountIncreasePercent.x, GameRule.refreshCountIncreasePercent.y) refreshNeedBaseballCount *= 1 + randf_range(GameRule.refreshCountIncreasePercent.x, GameRule.refreshCountIncreasePercent.y)
regenerateCards() regenerateCards()
) )
for feedScene in DirTool.listdir("res://components/Feeds"): for i in len(ComponentManager.feeds):
print("正在从 %s 加载饲料卡" % feedScene) print("正在从 %s 加载饲料卡" % ComponentManager.feeds[i])
var feed = load(feedScene).instantiate() as Feed var feed = ComponentManager.getFeed(i).instantiate() as Feed
feed.selected.connect( feed.selected.connect(
func(applied: bool): func(applied: bool):
if applied: if applied:
+1 -1
View File
@@ -33,7 +33,7 @@ func _ready():
queue_free() queue_free()
static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel: static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel:
var instance = load("res://components/UI/DamageLabel.tscn").instantiate() var instance = ComponentManager.getUIComponent("DamageLabel").instantiate()
instance.damage = spawnDamage instance.damage = spawnDamage
instance.crit = spawnCrit instance.crit = spawnCrit
instance.position = spawnPosition instance.position = spawnPosition
+1 -1
View File
@@ -126,7 +126,7 @@ func _ready():
UIState.energyPercent.setCurrent(newEnergy) UIState.energyPercent.setCurrent(newEnergy)
) )
for i in weapons: for i in weapons:
var icon: SkillIcon = load("res://components/Abstracts/SkillIconBase.tscn").instantiate() var icon: SkillIcon = ComponentManager.getUIComponent("SkillIcon").instantiate()
icon.weapon = i icon.weapon = i
UIState.skillIconContainer.add_child(icon) UIState.skillIconContainer.add_child(icon)
else: else:
+1 -1
View File
@@ -37,7 +37,7 @@ func _ready():
valueLabel.label_settings.font_color = Color(1, 1, 1) valueLabel.label_settings.font_color = Color(1, 1, 1)
static func create(newField: FieldStore.Entity, newValue: float, newShowSign: bool, newEntity: EntityBase, newUseViewCast: bool) -> FieldShow: static func create(newField: FieldStore.Entity, newValue: float, newShowSign: bool, newEntity: EntityBase, newUseViewCast: bool) -> FieldShow:
var fieldShow = load("res://components/UI/FieldShow.tscn").instantiate() var fieldShow = ComponentManager.getUIComponent("FieldShow").instantiate()
fieldShow.field = newField fieldShow.field = newField
fieldShow.value = newValue fieldShow.value = newValue
fieldShow.showSign = newShowSign fieldShow.showSign = newShowSign
+1 -1
View File
@@ -50,7 +50,7 @@ static func generate(
spawnPosition: Vector2, spawnPosition: Vector2,
addToWorld: bool = true addToWorld: bool = true
): ):
var instance: ItemDropped = load("res://components/UI/ItemDropped.tscn").instantiate() var instance: ItemDropped = ComponentManager.getUIComponent("ItemDropped").instantiate()
instance.item = itemType instance.item = itemType
instance.stackCount = count instance.stackCount = count
instance.position = spawnPosition instance.position = spawnPosition
+1 -1
View File
@@ -23,7 +23,7 @@ func _physics_process(_delta):
countLabel.text = str(count) countLabel.text = str(count)
static func generate(itemType: ItemStore.ItemType, itemCount: int = 1, isAutoFree: bool = false): static func generate(itemType: ItemStore.ItemType, itemCount: int = 1, isAutoFree: bool = false):
var item = load("res://components/UI/ItemShow.tscn").instantiate() var item = ComponentManager.getUIComponent("ItemShow").instantiate()
item.type = itemType item.type = itemType
item.count = itemCount item.count = itemCount
item.autoFree = isAutoFree item.autoFree = isAutoFree
+3 -3
View File
@@ -4,7 +4,7 @@ class_name Feed
signal selected(applied: bool) signal selected(applied: bool)
@export var avatarTexture: Texture2D = load("res://icon.svg") @export var avatarTexture: Texture2D = null
@export var displayName: String = "未命名饲料" @export var displayName: String = "未命名饲料"
@export var quality: FeedName.Quality = FeedName.Quality.COMMON @export var quality: FeedName.Quality = FeedName.Quality.COMMON
@export var topic: FeedName.Topic = FeedName.Topic.SURVIVAL @export var topic: FeedName.Topic = FeedName.Topic.SURVIVAL
@@ -69,7 +69,7 @@ func rebuildInfo():
noField = false noField = false
var field = fields[i] var field = fields[i]
var value = fieldValues[i] var value = fieldValues[i]
var fieldShow: FieldShow = load("res://components/UI/FieldShow.tscn").instantiate() var fieldShow: FieldShow = ComponentManager.getUIComponent("FieldShow").instantiate()
fieldShow.field = field fieldShow.field = field
fieldShow.value = value fieldShow.value = value
if is_instance_valid(UIState.player): if is_instance_valid(UIState.player):
@@ -82,7 +82,7 @@ func rebuildInfo():
for i in range(min(costs.size(), costCounts.size())): for i in range(min(costs.size(), costCounts.size())):
var cost = costs[i] var cost = costs[i]
var count = costCounts[i] var count = costCounts[i]
var costShow: ItemShow = load("res://components/UI/ItemShow.tscn").instantiate() var costShow: ItemShow = ComponentManager.getUIComponent("ItemShow").instantiate()
costShow.type = cost costShow.type = cost
costShow.count = int(count * multipiler()) costShow.count = int(count * multipiler())
costsBox.add_child(costShow) costsBox.add_child(costShow)
+1 -1
View File
@@ -2,7 +2,7 @@
extends PanelContainer extends PanelContainer
class_name Weapon class_name Weapon
@export var avatarTexture: Texture2D = load("res://icon.svg") @export var avatarTexture: Texture2D = null
@export var displayName: String = "未命名饲料" @export var displayName: String = "未命名饲料"
@export var quality: WeaponName.Quality = WeaponName.Quality.COMMON @export var quality: WeaponName.Quality = WeaponName.Quality.COMMON
@export var typeTopic: WeaponName.TypeTopic = WeaponName.TypeTopic.IMPACT @export var typeTopic: WeaponName.TypeTopic = WeaponName.TypeTopic.IMPACT
+1 -1
View File
@@ -23,4 +23,4 @@ static var idMap = {
ItemType.SOUL: "soul", ItemType.SOUL: "soul",
} }
static func getTexture(type: ItemType) -> Texture2D: static func getTexture(type: ItemType) -> Texture2D:
return load("res://resources/items/%s.svg" % idMap[type]) return ComponentManager.getItemTexture(idMap[type])
@@ -3,6 +3,10 @@ class_name ComponentManager
static var bullets = {} static var bullets = {}
static var characters = {} static var characters = {}
static var effects = {} static var effects = {}
static var feeds = []
static var uiComponents = {}
static var themes = {}
static var itemTextures = {}
static func init(): static func init():
for i in DirTool.listdir("res://components/Bullets"): for i in DirTool.listdir("res://components/Bullets"):
@@ -11,9 +15,27 @@ static func init():
characters[DirTool.getBasenameWithoutExtension(i)] = load(i) characters[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://components/Effects"): for i in DirTool.listdir("res://components/Effects"):
effects[DirTool.getBasenameWithoutExtension(i)] = load(i) effects[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://components/Feeds"):
feeds.append(load(i))
for i in DirTool.listdir("res://components/UI"):
uiComponents[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://themes"):
themes[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://resources/items"):
itemTextures[DirTool.getBasenameWithoutExtension(i)] = load("res://resources/items/%s" % i)
static func getBullet(name: String): static func getBullet(name: String):
return bullets[name] return bullets[name]
static func getCharacter(name: String): static func getCharacter(name: String):
return characters[name] return characters[name]
static func getEffect(name: String): static func getEffect(name: String):
return effects[name] return effects[name]
static func getFeed(index: int):
return feeds[index]
static func getUIComponent(name: String):
return uiComponents[name]
static func getTheme(name: String):
return themes[name]
static func getItemTexture(name: String):
return itemTextures[name]
static func readResource(path: String):
return load("res://resources/%s" % path)
+1 -1
View File
@@ -3,7 +3,7 @@ class_name QuickUI
static func smallText(text: String, center: bool = true): static func smallText(text: String, center: bool = true):
var label = Label.new() var label = Label.new()
label.text = text label.text = text
label.theme = load("res://themes/smallText.tres") label.theme = ComponentManager.getTheme("smallText")
if center: if center:
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
return label return label