修正godot代码里的字典  class_name RepresentManager
extends RefCounted

## 象征管理器
##
## 一个静态工具类，用于集中管理和访问所有“象征” (Represent) 资源。
## 使用字典进行缓存，以提供高效的查找功能。

#-----------------------------------------------------------------------------
# 象征资源定义
#-----------------------------------------------------------------------------



#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

## 根据名称字符串获取象征对象。
## @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 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, [])


#
### 获取所有已定义的象征。
### @return: 包含所有 Represent 对象的数组。
#static func get_all_represents() -> Array[Represent]:
	#_ensure_initialized()
	#return _represents_by_name.values()


## 检查一个象征是否有明确的对立象征。
## @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 = {
		# 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