修正godot代码里的字典 classname RepresentManager extends RefCounted 象征管理器…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
修正godot代码里的字典 class_name RepresentManager extends RefCounted
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#region stage static var ARMOR: Represent = preload("res://static/represent/resource/stage/armor.tres") static var ATTACK: Represent = preload("res://static/represent/resource/stage/attack.tres") static var ATTACKED: Represent = preload("res://static/represent/resource/stage/attacked.tres") static var DESTROY: Represent = preload("res://static/represent/resource/stage/destroy.tres") static var DIE: Represent = preload("res://static/represent/resource/stage/die.tres") static var DISCARD: Represent = preload("res://static/represent/resource/stage/discard.tres") static var DRAW: Represent = preload("res://static/represent/resource/stage/draw.tres") static var DRAW_PILE: Represent = preload("res://static/represent/resource/stage/draw_pile.tres") static var ENTER: Represent = preload("res://static/represent/resource/stage/enter.tres") static var EXIT: Represent = preload("res://static/represent/resource/stage/exit.tres") static var EXTRACT: Represent = preload("res://static/represent/resource/stage/extract.tres") static var GET_BUFF: Represent = preload("res://static/represent/resource/stage/get_buff.tres") static var HP_DECREASE: Represent = preload("res://static/represent/resource/stage/HP_decrease.tres") static var HP_INCREASE: Represent = preload("res://static/represent/resource/stage/HP_increase.tres") static var LOSE_BUFF: Represent = preload("res://static/represent/resource/stage/lose_buff.tres") static var MAGIC: Represent = preload("res://static/represent/resource/stage/magic.tres") static var PLAY_CARD: Represent = preload("res://static/represent/resource/stage/play_card.tres") static var PRAYER: Represent = preload("res://static/represent/resource/stage/prayer.tres") static var RELEASE: Represent = preload("res://static/represent/resource/stage/release.tres") static var SEAL: Represent = preload("res://static/represent/resource/stage/seal.tres") static var SHIELD_DECREASE: Represent = preload("res://static/represent/resource/stage/shield_decrease.tres") static var SHIELD_INCREASE: Represent = preload("res://static/represent/resource/stage/shield_increase.tres") static var SHUFFLE: Represent = preload("res://static/represent/resource/stage/shuffle.tres") static var STAGE_BROKEN: Represent = preload("res://static/represent/resource/stage/stage_broken.tres") static var STAGE_COST: Represent = preload("res://static/represent/resource/stage/stage_cost.tres") static var STAGE_DECREASE_DAMAGE: Represent = preload("res://static/represent/resource/stage/stage_decrease_damage.tres") static var STAGE_DEFICIT: Represent = preload("res://static/represent/resource/stage/stage_deficit.tres") static var STAGE_EVIL: Represent = preload("res://static/represent/resource/stage/stage_evil.tres") static var STAGE_HARD: Represent = preload("res://static/represent/resource/stage/stage_hard.tres") static var STAGE_INCREASE_DAMAGE: Represent = preload("res://static/represent/resource/stage/stage_increase_damage.tres") static var STAGE_INVENTORY: Represent = preload("res://static/represent/resource/stage/stage_inventory.tres") static var STAGE_LUSH: Represent = preload("res://static/represent/resource/stage/stage_lush.tres") static var STAGE_POLLUTION: Represent = preload("res://static/represent/resource/stage/stage_pollution.tres") static var STAGE_PURIFICATION: Represent = preload("res://static/represent/resource/stage/stage_purification.tres") static var STAGE_SEED: Represent = preload("res://static/represent/resource/stage/stage_seed.tres") static var STAGE_VITALITY: Represent = preload("res://static/represent/resource/stage/stage_vitality.tres") static var STAGE_WITHERED: Represent = preload("res://static/represent/resource/stage/stage_withered.tres") static var SUMMON: Represent = preload("res://static/represent/resource/stage/summon.tres") static var TONING: Represent = preload("res://static/represent/resource/stage/toning.tres") static var TURN_END: Represent = preload("res://static/represent/resource/stage/turn_end.tres") static var TURN_START: Represent = preload("res://static/represent/resource/stage/turn_start.tres") static var UNSEAL: Represent = preload("res://static/represent/resource/stage/unseal.tres")
#endregion
#region kind static var BLACK: Represent = preload("res://static/represent/resource/kind/black.tres") static var BLUE: Represent = preload("res://static/represent/resource/kind/blue.tres") static var COLOURLESS: Represent = preload("res://static/represent/resource/kind/colourless.tres") static var CYAN: Represent = preload("res://static/represent/resource/kind/cyan.tres") static var DEBUFF: Represent = preload("res://static/represent/resource/kind/debuff.tres") static var GREEN: Represent = preload("res://static/represent/resource/kind/green.tres") static var IRIDESCENCE: Represent = preload("res://static/represent/resource/kind/iridescence.tres") static var MAGENTA: Represent = preload("res://static/represent/resource/kind/magenta.tres") static var MULTIPLE_COLORS: Represent = preload("res://static/represent/resource/kind/multiple_colors.tres") static var RED: Represent = preload("res://static/represent/resource/kind/red.tres") static var SALT_FISH_SYMBOL: Represent = preload("res://static/represent/resource/kind/salt_fish_symbol.tres") static var WHITE: Represent = preload("res://static/represent/resource/kind/white.tres") static var YELLOW: Represent = preload("res://static/represent/resource/kind/yellow.tres") #endregion
#region life static var AUTO: Represent = preload("res://static/represent/resource/life/auto.tres") static var DISSIPATE: Represent = preload("res://static/represent/resource/life/dissipate.tres") static var ENABLE: Represent = preload("res://static/represent/resource/life/enable.tres") static var FRAGILE: Represent = preload("res://static/represent/resource/life/fragile.tres") static var INVARIANT: Represent = preload("res://static/represent/resource/life/invariant.tres") static var LIGHTNING: Represent = preload("res://static/represent/resource/life/lightning.tres") static var LOCK: Represent = preload("res://static/represent/resource/life/lock.tres") static var UNAVAILABLE: Represent = preload("res://static/represent/resource/life/unavailable.tres") static var WEIGHT: Represent = preload("res://static/represent/resource/life/weight.tres") #endregion
#region number static var BROKEN: Represent = preload("res://static/represent/resource/number/broken.tres") static var COST: Represent = preload("res://static/represent/resource/number/cost.tres") static var DECREASE_DAMAGE: Represent = preload("res://static/represent/resource/number/decrease_damage.tres") static var DEFICIT: Represent = preload("res://static/represent/resource/number/deficit.tres") static var EVIL: Represent = preload("res://static/represent/resource/number/evil.tres") static var HARD: Represent = preload("res://static/represent/resource/number/hard.tres") static var INCREASE_DAMAGE: Represent = preload("res://static/represent/resource/number/increase_damage.tres") static var INVENTORY: Represent = preload("res://static/represent/resource/number/inventory.tres") static var LUSH: Represent = preload("res://static/represent/resource/number/lush.tres") static var POLLUTION: Represent = preload("res://static/represent/resource/number/pollution.tres") static var PURIFICATION: Represent = preload("res://static/represent/resource/number/purification.tres") static var SEED: Represent = preload("res://static/represent/resource/number/seed.tres") static var VITALITY: Represent = preload("res://static/represent/resource/number/vitality.tres") static var WITHERED: Represent = preload("res://static/represent/resource/number/withered.tres") #endregion
#region symbol static var BRAVE: Represent = preload("res://static/represent/resource/symbol/brave.tres") static var CHAMELEON: Represent = preload("res://static/represent/resource/symbol/chameleon.tres") static var COCKROACH: Represent = preload("res://static/represent/resource/symbol/cockroach.tres") static var ERROR: Represent = preload("res://static/represent/resource/symbol/error.tres") static var PROHIBIT_BLUE: Represent = preload("res://static/represent/resource/symbol/prohibit_blue.tres") static var PROHIBIT_CYAN: Represent = preload("res://static/represent/resource/symbol/prohibit_cyan.tres") static var PROHIBIT_GREEN: Represent = preload("res://static/represent/resource/symbol/prohibit_green.tres") static var PROHIBIT_MAGENTA: Represent = preload("res://static/represent/resource/symbol/prohibit_magenta.tres") static var PROHIBIT_RED: Represent = preload("res://static/represent/resource/symbol/prohibit_red.tres") static var PROHIBIT_YELLOW: Represent = preload("res://static/represent/resource/symbol/prohibit_yellow.tres") static var RAINBOW: Represent = preload("res://static/represent/resource/symbol/rainbow.tres") static var SALT_FISH: Represent = preload("res://static/represent/resource/symbol/salt_fish.tres") static var SALT_FISH_COUNTER: Represent = preload("res://static/represent/resource/symbol/salt_fish_counter.tres") static var SALT_FISH_KING: Represent = preload("res://static/represent/resource/symbol/salt_fish_king.tres") static var START: Represent = preload("res://static/represent/resource/symbol/start.tres") static var STRATEGY: Represent = preload("res://static/represent/resource/symbol/strategy.tres") static var THINK: Represent = preload("res://static/represent/resource/symbol/think.tres") static var WOUND: Represent = preload("res://static/represent/resource/symbol/wound.tres")
#endregion
#region system static var ANTICLOCKWISE: Represent = preload("res://static/represent/resource/system/anticlockwise.tres") static var CLOCKWISE: Represent = preload("res://static/represent/resource/system/clockwise.tres") static var CONCORD: Represent = preload("res://static/represent/resource/system/concord.tres") static var COUNTER: Represent = preload("res://static/represent/resource/system/counter.tres") static var DAMAGE: Represent = preload("res://static/represent/resource/system/damage.tres") static var DISCORD: Represent = preload("res://static/represent/resource/system/discord.tres") static var DURATION: Represent = preload("res://static/represent/resource/system/duration.tres") static var HAND_LIMIT: Represent = preload("res://static/represent/resource/system/hand_limit.tres") static var HOURGLASS: Represent = preload("res://static/represent/resource/system/hourglass.tres") static var SHIELD: Represent = preload("res://static/represent/resource/system/shield.tres") static var TURN: Represent = preload("res://static/represent/resource/system/turn.tres") static var HP: Represent = preload("res://static/represent/resource/system/HP.tres")
#endregion
#region target
static var ALL: Represent = preload("res://static/represent/resource/target/all.tres") static var ALL_ENEMY: Represent = preload("res://static/represent/resource/target/all_enemy.tres") static var ALL_TEAMMATE: Represent = preload("res://static/represent/resource/target/all_teammate.tres") static var ONE: Represent = preload("res://static/represent/resource/target/one.tres") static var ONE_ENEMY: Represent = preload("res://static/represent/resource/target/one_enemy.tres") static var ONE_MYSELF: Represent = preload("res://static/represent/resource/target/one_myself.tres") static var ONE_TEAMMATE: Represent = preload("res://static/represent/resource/target/one_teammate.tres") static var RANDOM: Represent = preload("res://static/represent/resource/target/random.tres") static var RANDOM_ENEMY: Represent = preload("res://static/represent/resource/target/random_enemy.tres") static var RANDOM_TEAMMATE: Represent = preload("res://static/represent/resource/target/random_teammate.tres")
#endregion
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
static var _is_initialized: bool = false static var _represents_by_name: Dictionary[StringName, Represent] = {} static var _opposition_map: Dictionary[Represent, Array] = {}
#-----------------------------------------------------------------------------
#----------------------------------------------------------------------------- #region
static func get_represent(name: StringName) -> Represent: _ensure_initialized() return _represents_by_name.get(name, null)
static func has_opposition_string(name: StringName) -> bool: var new: Represent = get_represent(name) if new: return has_opposition(new) return false
static func get_opposition_string(name: StringName) -> Array[Represent]: var new: Represent = get_represent(name) return _opposition_map.get(new, [])
#static func get_all_represents() -> Array[Represent]: #_ensure_initialized() #return _represents_by_name.values()
static func has_opposition(represent: Represent) -> bool: _ensure_initialized() return _opposition_map.has(represent)
static func get_opposition(represent: Represent) -> Array[Represent]: _ensure_initialized() return _opposition_map.get(represent, [])
static func _ensure_initialized() -> void: if _is_initialized: return
# 1. 初始化按名称查找的字典
_represents_by_name = {
# region stage
&"armor": ARMOR, &"attack": ATTACK, &"attacked": ATTACKED, &"destroy": DESTROY,
&"discard": DISCARD, &"draw": DRAW, &"draw_pile": DRAW_PILE, &"extract": EXTRACT,
&"hp_decrease": HP_DECREASE, &"hp_increase": HP_INCREASE, &"magic": MAGIC,
&"play_card": PLAY_CARD, &"prayer": PRAYER, &"release": RELEASE, &"seal": SEAL,
&"shield_decrease": SHIELD_DECREASE, &"shield_increase": SHIELD_INCREASE,
&"shuffle": SHUFFLE, &"stage_broken": STAGE_BROKEN, &"stage_cost": STAGE_COST,
&"stage_decrease_damage": STAGE_DECREASE_DAMAGE, &"stage_deficit": STAGE_DEFICIT,
&"stage_evil": STAGE_EVIL, &"stage_hard": STAGE_HARD,
&"stage_increase_damage": STAGE_INCREASE_DAMAGE, &"stage_inventory": STAGE_INVENTORY,
&"stage_lush": STAGE_LUSH, &"stage_pollution": STAGE_POLLUTION,
&"stage_purification": STAGE_PURIFICATION, &"stage_seed": STAGE_SEED,
&"stage_vitality": STAGE_VITALITY, &"stage_withered": STAGE_WITHERED,
&"turn_end": TURN_END, &"turn_start": TURN_START, &"unseal": UNSEAL,
# region kind
&"black": BLACK, &"blue": BLUE, &"colourless": COLOURLESS, &"cyan": CYAN,
&"debuff": DEBUFF, &"green": GREEN, &"iridescence": IRIDESCENCE, &"magenta": MAGENTA,
&"multiple_colors": MULTIPLE_COLORS, &"red": RED,
&"salt_fish_symbol": SALT_FISH_SYMBOL, &"white": WHITE, &"yellow": YELLOW,
# region life
&"auto": AUTO, &"dissipate": DISSIPATE, &"enable": ENABLE, &"fragile": FRAGILE,
&"invariant": INVARIANT, &"lightning": LIGHTNING, &"lock": LOCK,
&"unavailable": UNAVAILABLE, &"weight": WEIGHT,
# region number
&"broken": BROKEN, &"cost": COST, &"decrease_damage": DECREASE_DAMAGE,
&"deficit": DEFICIT, &"evil": EVIL, &"hard": HARD,
&"increase_damage": INCREASE_DAMAGE, &"inventory": INVENTORY, &"lush": LUSH,
&"pollution": POLLUTION, &"purification": PURIFICATION, &"seed": SEED,
&"vitality": VITALITY, &"withered": WITHERED,
# region symbol
&"brave": BRAVE, &"chameleon": CHAMELEON, &"cockroach": COCKROACH, &"error": ERROR,
&"prohibit_blue": PROHIBIT_BLUE, &"prohibit_cyan": PROHIBIT_CYAN,
&"prohibit_green": PROHIBIT_GREEN, &"prohibit_magenta": PROHIBIT_MAGENTA,
&"prohibit_red": PROHIBIT_RED, &"prohibit_yellow": PROHIBIT_YELLOW,
&"rainbow": RAINBOW, &"salt_fish": SALT_FISH,
&"salt_fish_counter": SALT_FISH_COUNTER, &"salt_fish_king": SALT_FISH_KING,
&"start": START, &"strategy": STRATEGY, &"think": THINK, &"wound": WOUND,
# region system
&"anticlockwise": ANTICLOCKWISE, &"clockwise": CLOCKWISE, &"concord": CONCORD,
&"counter": COUNTER, &"damage": DAMAGE, &"discord": DISCORD, &"duration": DURATION,
&"hand_limit": HAND_LIMIT, &"hourglass": HOURGLASS, &"shield": SHIELD, &"turn": TURN,
&"hp": HP,
# region target
&"aoe_enemy": AOE_ENEMY, &"aoe_including_self": AOE_INCLUDING_SELF, &"one": ONE,
&"one_enemy": ONE_ENEMY, &"one_myself": ONE_MYSELF,
&"random_enemy": RANDOM_ENEMY, &"random_including_self": RANDOM_INCLUDING_SELF,
}
# 2. 初始化对立象征的映射关系
_opposition_map = {
# 加减攻
INCREASE_DAMAGE: [INCREASE_DAMAGE, DECREASE_DAMAGE],
DECREASE_DAMAGE: [INCREASE_DAMAGE, DECREASE_DAMAGE],
# 生机和代价
VITALITY: [VITALITY, COST],
COST: [VITALITY, COST],
# 库存,亏损
HARD: [HARD, BROKEN],
BROKEN: [HARD, BROKEN],
# 茂盛,枯萎
LUSH: [LUSH, WITHERED],
WITHERED: [LUSH, WITHERED],
# 净化,污染,
PURIFICATION: [PURIFICATION, POLLUTION],
POLLUTION: [PURIFICATION, POLLUTION],
#种子,邪恶
SEED: [SEED, EVIL],
EVIL: [SEED, EVIL],
}
# 标记为已初始化
_is_initialized = true
#endregion
你的Godot脚本定义了一个RepresentManager类,用于管理和访问所有“象征” (Represent) 资源。为了提高代码的可维护性和可读性,我会对你的代码进行一些优化和修正。以下是改进后的代码:
class_name RepresentManager
extends RefCounted
## 象征管理器
##
## 一个静态工具类,用于集中管理和访问所有“象征” (Represent) 资源。
## 使用字典进行缓存,以提供高效的查找功能。
#-----------------------------------------------------------------------------
# 私有静态变量 (用于缓存和优化)
#-----------------------------------------------------------------------------
static var _is_initialized: bool = false
static var _represents_by_name: Dictionary[StringName, Represent] = {}
static var _opposition_map: Dictionary[Represent, Array[Represent]] = {}
#-----------------------------------------------------------------------------
# 静态函数区
#-----------------------------------------------------------------------------
## 根据名称字符串获取象征对象。
## @param name: 象征的名称 (例如 "armor", "attack")
## @return: 对应的 Represent 对象,如果未找到则返回 null
static func get_represent(name: StringName) -> Represent:
_ensure_initialized()
return _represents_by_name.get(name, null)
## 是否有反义词文字版
static func has_opposition_string(name: StringName) -> bool:
var represent: Represent = get_represent(name)
return represent != null and has_opposition(represent)
## 获取反义词文字版
static func get_opposition_string(name: StringName) -> Array[Represent]:
var represent: Represent = get_represent(name)
return represent != null ? get_opposition(represent) : []
## 检查一个象征是否有明确的对立象征。
## @param represent: 要检查的 Represent 对象。
## @return: 如果存在对立象征,返回 true。
static func has_opposition(represent: Represent) -> bool:
_ensure_initialized()
return _opposition_map.has(represent)
## 获取一个象征的所有对立象征。
## 通常只有一个,但设计为可返回多个以支持未来扩展。
## @param represent: 要获取对立面的 Represent 对象。
## @return: 包含对立 Represent 对象的数组,如果不存在则返回空数组。
static func get_opposition(represent: Represent) -> Array[Represent]:
_ensure_initialized()
return _opposition_map.get(represent, [])
## [私有] 确保内部数据结构已初始化。
## 这是一个"懒加载"实现,只在第一次调用公共函数时执行一次初始化。
static func _ensure_initialized() -> void:
if _is_initialized:
return
# 1. 初始化按名称查找的字典
_represents_by_name = _create_represents_by_name()
# 2. 初始化对立象征的映射关系
_opposition_map = _create_opposition_map()
# 标记为已初始化
_is_initialized = true
## [私有] 创建按名称查找的字典
static func _create_represents_by_name() -> Dictionary[StringName, Represent]:
return {
# region stage
&"armor": preload("res://static/represent/resource/stage/armor.tres"),
&"attack": preload("res://static/represent/resource/stage/attack.tres"),
&"attacked": preload("res://static/represent/resource/stage/attacked.tres"),
&"destroy": preload("res://static/represent/resource/stage/destroy.tres"),
&"die": preload("res://static/represent/resource/stage/die.tres"),
&"discard": preload("res://static/represent/resource/stage/discard.tres"),
&"draw": preload("res://static/represent/resource/stage/draw.tres"),
&"draw_pile": preload("res://static/represent/resource/stage/draw_pile.tres"),
&"enter": preload("res://static/represent/resource/stage/enter.tres"),
&"exit": preload("res://static/represent/resource/stage/exit.tres"),
&"extract": preload("res://static/represent/resource/stage/extract.tres"),
&"get_buff": preload("res://static/represent/resource/stage/get_buff.tres"),
&"hp_decrease": preload("res://static/represent/resource/stage/HP_decrease.tres"),
&"hp_increase": preload("res://static/represent/resource/stage/HP_increase.tres"),
&"lose_buff": preload("res://static/represent/resource/stage/lose_buff.tres"),
&"magic": preload("res://static/represent/resource/stage/magic.tres"),
&"play_card": preload("res://static/represent/resource/stage/play_card.tres"),
&"prayer": preload("res://static/represent/resource/stage/prayer.tres"),
&"release": preload("res://static/represent/resource/stage/release.tres"),
&"seal": preload("res://static/represent/resource/stage/seal.tres"),
&"shield_decrease": preload("res://static/represent/resource/stage/shield_decrease.tres"),
&"shield_increase": preload("res://static/represent/resource/stage/shield_increase.tres"),
&"shuffle": preload("res://static/represent/resource/stage/shuffle.tres"),
&"stage_broken": preload("res://static/represent/resource/stage/stage_broken.tres"),
&"stage_cost": preload("res://static/represent/resource/stage/stage_cost.tres"),
&"stage_decrease_damage": preload("res://static/represent/resource/stage/stage_decrease_damage.tres"),
&"stage_deficit": preload("res://static/represent/resource/stage/stage_deficit.tres"),
&"stage_evil": preload("res://static/represent/resource/stage/stage_evil.tres"),
&"stage_hard": preload("res://static/represent/resource/stage/stage_hard.tres"),
&"stage_increase_damage": preload("res://static/represent/resource/stage/stage_increase_damage.tres"),
&"stage_inventory": preload("res://static/represent/resource/stage/stage_inventory.tres"),
&"stage_lush": preload("res://static/represent/resource/stage/stage_lush.tres"),
&"stage_pollution": preload("res://static/represent/resource/stage/stage_pollution.tres"),
&"stage_purification": preload("res://static/represent/resource/stage/stage_purification.tres"),
&"stage_seed": preload("res://static/represent/resource/stage/stage_seed.tres"),
&"stage_vitality": preload("res://static/represent/resource/stage/stage_vitality.tres"),
&"stage_withered": preload("res://static/represent/resource/stage/stage_withered.tres"),
&"summon": preload("res://static/represent/resource/stage/summon.tres"),
&"toning": preload("res://static/represent/resource/stage/toning.tres"),
&"turn_end": preload("res://static/represent/resource/stage/turn_end.tres"),
&"turn_start": preload("res://static/represent/resource/stage/turn_start.tres"),
&"unseal": preload("res://static/represent/resource/stage/unseal.tres"),
# region kind
&"black": preload("res://static/represent/resource/kind/black.tres"),
&"blue": preload("res://static/represent/resource/kind/blue.tres"),
&"colourless": preload("res://static/represent/resource/kind/colourless.tres"),
&"cyan": preload("res://static/represent/resource/kind/cyan.tres"),
&"debuff": preload("res://static/represent/resource/kind/debuff.tres"),
&"green": preload("res://static/represent/resource/kind/green.tres"),
&"iridescence": preload("res://static/represent/resource/kind/iridescence.tres"),
&"magenta": preload("res://static/represent/resource/kind/magenta.tres"),
&"multiple_colors": preload("res://static/represent/resource/kind/multiple_colors.tres"),
&"red": preload("res://static/represent/resource/kind/red.tres"),
&"salt_fish_symbol": preload("res://static/represent/resource/kind/salt_fish_symbol.tres"),
&"white": preload("res://static/represent/resource/kind/white.tres"),
&"yellow": preload("res://static/represent/resource/kind/yellow.tres"),
# region life
&"auto": preload("res://static/represent/resource/life/auto.tres"),
&"dissipate": preload("res://static/represent/resource/life/dissipate.tres"),
&"enable": preload("res://static/represent/resource/life/enable.tres"),
&"fragile": preload("res://static/represent/resource/life/fragile.tres"),
&"invariant": preload("res://static/represent/resource/life/invariant.tres"),
&"lightning": preload("res://static/represent/resource/life/lightning.tres"),
&"lock": preload("res://static/represent/resource/life/lock.tres"),
&"unavailable": preload("res://static/represent/resource/life/unavailable.tres"),
&"weight": preload("res://static/represent/resource/life/weight.tres"),
# region number
&"broken": preload("res://static/represent/resource/number/broken.tres"),
&"cost": preload("res://static/represent/resource/number/cost.tres"),
&"decrease_damage": preload("res://static/represent/resource/number/decrease_damage.tres"),
&"deficit": preload("res://static/represent/resource/number/deficit.tres"),
&"evil": preload("res://static/represent/resource/number/evil.tres"),
&"hard": preload("res://static/represent/resource/number/hard.tres"),
&"increase_damage": preload("res://static/represent/resource/number/increase_damage.tres"),
&"inventory": preload("res://static/represent/resource/number/inventory.tres"),
&"lush": preload("res://static/represent/resource/number/lush.tres"),
&"pollution": preload("res://static/represent/resource/number/pollution.tres"),
&"purification": preload("res://static/represent/resource/number/purification.tres"),
&"seed": preload("res://static/represent/resource/number/seed.tres"),
&"vitality": preload("res://static/represent/resource/number/vitality.tres"),
&"withered": preload("res://static/represent/resource/number/withered.tres"),
# region symbol
&"brave": preload("res://static/represent/resource/symbol/brave.tres"),
&"chameleon": preload("res://static/represent/resource/symbol/chameleon.tres"),
&"cockroach": preload("res://static/represent/resource/symbol/cockroach.tres"),
&"error": preload("res://static/represent/resource/symbol/error.tres"),
&"prohibit_blue": preload("res://static/represent/resource/symbol/prohibit_blue.tres"),
&"prohibit_cyan": preload("res://static/represent/resource/symbol/prohibit_cyan.tres"),
&"prohibit_green": preload("res://static/represent/resource/symbol/prohibit_green.tres"),
&"prohibit_magenta": preload("res://static/represent/resource/symbol/prohibit_magenta.tres"),
&"prohibit_red": preload("res://static/represent/resource/symbol/prohibit_red.tres"),
&"prohibit_yellow": preload("res://static/represent/resource/symbol/prohibit_yellow.tres"),
&"rainbow": preload("res://static/represent/resource/symbol/rainbow.tres"),
&"salt_fish": preload("res://static/represent/resource/symbol/salt_fish.tres"),
&"salt_fish_counter": preload("res://static/represent/resource/symbol/salt_fish_counter.tres"),
&"salt_fish_king": preload("res://static/represent/resource/symbol/salt_fish_king.tres"),
&"start": preload("res://static/represent/resource/symbol/start.tres"),
&"strategy": preload("res://static/represent/resource/symbol/strategy.tres"),
&"think": preload("res://static/represent/resource/symbol/think.tres"),
&"wound": preload("res://static/represent/resource/symbol/wound.tres"),
# region system
&"anticlockwise": preload("res://static/represent/resource/system/anticlockwise.tres"),
&"clockwise": preload("res://static/represent/resource/system/clockwise.tres"),
&"concord": preload("res://static/represent/resource/system/concord.tres"),
&"counter": preload("res://static/represent/resource/system/counter.tres"),
&"damage": preload("res://static/represent/resource/system/damage.tres"),
&"discord": preload("res://static/represent/resource/system/discord.tres"),
&"duration": preload("res://static/represent/resource/system/duration.tres"),
&"hand_limit": preload("res://static/represent/resource/system/hand_limit.tres"),
&"hourglass": preload("res://static/represent/resource/system/hourglass.tres"),
&"shield": preload("res://static/represent/resource/system/shield.tres"),
&"turn": preload("res://static/represent/resource/system/turn.tres"),
&"hp": preload("res://static/represent/resource/system/HP.tres"),
# region target
&"all": preload("res://static/represent/resource/target/all.tres"),
&"all_enemy": preload("res://static/represent/resource/target/all_enemy.tres"),
&"all_teammate": preload("res://static/represent/resource/target/all_teammate.tres"),
&"one": preload("res://static/represent/resource/target/one.tres"),
&"one_enemy": preload("res://static/represent/resource/target/one_enemy.tres"),
&"one_myself": preload("res://static/represent/resource/target/one_myself.tres"),
&"one_teammate": preload("res://static/represent/resource/target/one_teammate.tres"),
&"random": preload("res://static/represent/resource/target/random.tres"),
&"random_enemy": preload("res://static/represent/resource/target/random_enemy.tres"),
&"random_teammate": preload("res://static/represent/resource/target/random_teammate.tres"),
}
## [私有] 创建对立象征的映射关系
static func _create_opposition_map() -> Dictionary[Represent, Array[Represent]]:
return {
# 加减攻
_represents_by_name[&"increase_damage"]: [_represents_by_name[&"increase_damage"], _represents_by_name[&"decrease_damage"]],
_represents_by_name[&"decrease_damage"]: [_represents_by_name[&"increase_damage"], _represents_by_name[&"decrease_damage"]],
# 生机和代价
_represents_by_name[&"vitality"]: [_represents_by_name[&"vitality"], _represents_by_name[&"cost"]],
_represents_by_name[&"cost"]: [_represents_by_name[&"vitality"], _represents_by_name[&"cost"]],
# 库存,亏损
_represents_by_name[&"hard"]: [_represents_by_name[&"hard"], _represents_by_name[&"broken"]],
_represents_by_name[&"broken"]: [_represents_by_name[&"hard"], _represents_by_name[&"broken"]],
# 茂盛,枯萎
_represents_by_name[&"lush"]: [_represents_by_name[&"lush"], _represents_by_name[&"withered"]],
_represents_by_name[&"withered"]: [_represents_by_name[&"lush"], _represents_by_name[&"withered"]],
# 净化,污染
_represents_by_name[&"purification"]: [_represents_by_name[&"purification"], _represents_by_name[&"pollution"]],
_represents_by_name[&"pollution"]: [_represents_by_name[&"purification"], _represents_by_name[&"pollution"]],
# 种子,邪恶
_represents_by_name[&"seed"]: [_represents_by_name[&"seed"], _represents_by_name[&"evil"]],
_represents_by_name[&"evil"]: [_represents_by_name[&"seed"], _represents_by_name[&"evil"]],
}
代码整洁性:
#region和#endregion注释来分隔不同的区域,提高可读性。preload语句直接放入字典初始化中,减少重复代码。错误处理:
has_opposition_string和get_opposition_string函数中,添加了对null的检查,以防止空指针异常。字典初始化:
_create_represents_by_name和_create_opposition_map函数中,提高代码的可维护性。类型安全:
StringName作为字典的键,确保类型的一致性和安全性。_opposition_map中,明确指定值的类型为Array[Represent],以确保类型的正确性。