1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 15:01:53 +08:00

refactor(资源加载): 将preload替换为load以优化内存使用

统一使用load方法动态加载资源,减少启动时的内存占用
移动Manager类到Tools/Managers目录下
修复DirTool处理remap文件的问题
This commit is contained in:
2025-09-21 12:53:15 +08:00
parent 9f82b7f9fa
commit 4c5842fb9e
30 changed files with 64 additions and 60 deletions
+8 -8
View File
@@ -39,7 +39,7 @@ func attack(type):
playSound("attack0")
for i in randi_range(20, 30):
if !is_instance_valid(currentFocusedBoss): return false
for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/ArrowSeven.tscn"), self, findWeaponAnchor("normal"), deg_to_rad(randf_range(0, 360))):
for bullet in BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/ArrowSeven.tscn"), self, findWeaponAnchor("normal"), deg_to_rad(randf_range(0, 360))):
bullet.tracer = currentFocusedBoss
bullet.position += MathTool.randv2_range(50)
await TickTool.millseconds(50)
@@ -48,10 +48,10 @@ func attack(type):
await sprintTo(currentFocusedBoss.position - Vector2(MathTool.randc_from([-300, 300]), 300), 0.25)
var count = randi_range(6, 8)
for i in range(count):
BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/SunDance.tscn"), self, weaponPos, deg_to_rad(360.0 / count * i))
BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/SunDance.tscn"), self, weaponPos, deg_to_rad(360.0 / count * i))
elif type == 2:
for i in range(13):
for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/ForeverRainbow.tscn"), self, weaponPos, 0):
for bullet in BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/ForeverRainbow.tscn"), self, weaponPos, 0):
bullet.rotation = 360 / 13.0 * i
elif type == 3:
if !is_instance_valid(currentFocusedBoss): return false
@@ -61,7 +61,7 @@ func attack(type):
currentInvinsible = true
playSound("attack3")
await TickTool.millseconds(500)
BulletBase.generate(preload("res://components/Bullets/BearSprint.tscn"), self, weaponPos, 0)
BulletBase.generate(load("res://components/Bullets/BearSprint.tscn"), self, weaponPos, 0)
await trySprint()
sprintParticle.emitting = false
canRunAi = true
@@ -73,7 +73,7 @@ func attack(type):
var count = randi_range(8, 12)
for i in range(count):
if !is_instance_valid(currentFocusedBoss): return false
for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/ArrowSeven.tscn"), self, findWeaponAnchor("normal"), deg_to_rad(360.0 / count * i)):
for bullet in BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/ArrowSeven.tscn"), self, findWeaponAnchor("normal"), deg_to_rad(360.0 / count * i)):
bullet.tracer = currentFocusedBoss
await TickTool.millseconds(830.0 / count)
return false
@@ -82,7 +82,7 @@ func attack(type):
var count = randi_range(20, 30)
for i in range(count):
if !is_instance_valid(currentFocusedBoss): return false
for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0):
for bullet in BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0):
bullet.rotation = deg_to_rad(360.0 / count * i)
await TickTool.millseconds(1670.0 / count)
return false
@@ -90,7 +90,7 @@ func attack(type):
playSound("attack6")
for i in 16:
if !is_instance_valid(currentFocusedBoss): return false
for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0):
for bullet in BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0):
bullet.position += MathTool.randv2_range(600)
bullet.look_at(currentFocusedBoss.position + MathTool.randv2_range(50))
await TickTool.millseconds(100)
@@ -102,7 +102,7 @@ func attack(type):
if !is_instance_valid(currentFocusedBoss): return false
playSound("attack7")
for i in 16:
for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0):
for bullet in BulletBase.generate(load("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0):
bullet.rotation_degrees += initAngle
bullet.rotation -= angle / 2
bullet.rotation += angle / 16 * i
+4 -4
View File
@@ -26,19 +26,19 @@ func attack(type):
if type == 0:
var weaponPos = findWeaponAnchor("normal")
for i in randi_range(10, 20):
BulletBase.generate(preload("res://components/Bullets/Diamond.tscn"), self, weaponPos + MathTool.randv2_range(20), rotation + deg_to_rad(randf_range(-90, 90)))
BulletBase.generate(load("res://components/Bullets/Diamond.tscn"), self, weaponPos + MathTool.randv2_range(20), rotation + deg_to_rad(randf_range(-90, 90)))
elif type == 1:
var laserCount = randi_range(2, 4)
for i in laserCount:
BulletBase.generate(preload("res://components/Bullets/ChickLaser.tscn"), self, texture.global_position, deg_to_rad(360.0 / laserCount * i))
BulletBase.generate(load("res://components/Bullets/ChickLaser.tscn"), self, texture.global_position, deg_to_rad(360.0 / laserCount * i))
elif type == 2:
var weaponPos = findWeaponAnchor("normal")
var target = weaponPos.angle_to_point(currentFocusedBoss.position)
firepot.global_rotation = target
firepot.shot()
BulletBase.generate(preload("res://components/Bullets/FireScan.tscn"), self, weaponPos, target)
BulletBase.generate(load("res://components/Bullets/FireScan.tscn"), self, weaponPos, target)
elif type == 3:
BulletBase.generate(preload("res://components/Bullets/ChickSprint.tscn"), self, position, 0)
BulletBase.generate(load("res://components/Bullets/ChickSprint.tscn"), self, position, 0)
trySprint()
return true
func sprint():
+1 -1
View File
@@ -14,5 +14,5 @@ func attack(type):
if type == 0:
var weaponPos = findWeaponAnchor("normal")
for i in randi_range(1, 4):
BulletBase.generate(preload("res://components/Bullets/Star.tscn"), self, weaponPos, (currentFocusedBoss.position - position).angle())
BulletBase.generate(load("res://components/Bullets/Star.tscn"), self, weaponPos, (currentFocusedBoss.position - position).angle())
return true
+2 -2
View File
@@ -16,9 +16,9 @@ func ai():
tryKill()
func attack(type):
if type == 0:
BulletBase.generate(preload("res://components/Bullets/PurpleCrystalSmall.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
BulletBase.generate(load("res://components/Bullets/PurpleCrystalSmall.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
await TickTool.millseconds(randi_range(5, 25))
elif type == 1:
BulletBase.generate(preload("res://components/Bullets/BossAttack/KukeMC/HeavyCrystal.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
BulletBase.generate(load("res://components/Bullets/BossAttack/KukeMC/HeavyCrystal.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
func kill():
masterMine.tryHeal(100)
+4 -4
View File
@@ -34,11 +34,11 @@ func attack(type):
if type == 0:
for i in randi_range(8, 16):
fields[FieldStore.Entity.OFFSET_SHOOT] = 25
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
BulletBase.generate(load("res://components/Bullets/PurpleCrystal.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
await TickTool.millseconds(randi_range(10, 50))
elif type == 1 and health < fields[FieldStore.Entity.MAX_HEALTH] * 0.5 and canSummon:
for i in randi_range(1, 2):
var child = EntityBase.generate(preload("res://components/Characters/KukeChild.tscn"), position + MathTool.randv2_range(500))
var child = EntityBase.generate(load("res://components/Characters/KukeChild.tscn"), position + MathTool.randv2_range(500))
child.currentFocusedBoss = currentFocusedBoss
child.masterMine = self
elif type == 2:
@@ -47,7 +47,7 @@ func attack(type):
for bulletIndex in countOfBullet:
for branchIndex in countOfBranch:
fields[FieldStore.Entity.OFFSET_SHOOT] = 0
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, findWeaponAnchor("normal"), deg_to_rad(360.0 / countOfBullet * bulletIndex + 360.0 / countOfBranch * branchIndex))
BulletBase.generate(load("res://components/Bullets/PurpleCrystal.tscn"), self, findWeaponAnchor("normal"), deg_to_rad(360.0 / countOfBullet * bulletIndex + 360.0 / countOfBranch * branchIndex))
await TickTool.millseconds(100)
elif type == 3:
BulletBase.generate(preload("res://components/Bullets/BossAttack/KukeMC/HeavyCrystal.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))
BulletBase.generate(load("res://components/Bullets/BossAttack/KukeMC/HeavyCrystal.tscn"), self, findWeaponAnchor("normal"), position.angle_to_point(currentFocusedBoss.position))