local BattleConst = require "app/module/battle/battle_const"
local BattleNumberComp = class("BattleNumberComp", LuaComponent)

function BattleNumberComp:init()
	local uiMap = self.baseObject:genAllChildren()
	self.animator = self.baseObject:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR)
	self.effectText = uiMap["battle_number.text_number"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT)
	if not self.effectText then
		self.effectText = uiMap["battle_number.text_number"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
	end
	self.time = 0
	self.comboText = uiMap["battle_number.text_combo"]
	self.comboText:setText(I18N:getGlobalText(I18N.GlobalConst.COMBO_DESC))
end

function BattleNumberComp:showEffectNumber(effectType, num, x, y, showCombo)
	self.comboText:setVisible(showCombo == true)
	self.effectText.text = tostring(num)
	self.baseObject:setLocalPosition(x, y, 0)

	if effectType == BattleConst.EFFECT_TYPE_MOVE_L then
		self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_MOVE_L, -1, 0)
	elseif effectType == BattleConst.EFFECT_TYPE_MOVE_R then
		self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_MOVE_R, -1, 0)
	elseif effectType == BattleConst.EFFECT_TYPE_CRIT then
		self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_CRIT, -1, 0)
	else
		self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_BUFF, -1, 0)
	end
	self.time = 1.367
end

function BattleNumberComp:setEnabled(enabled)
	local scale = enabled and 1 or 0
	self.baseObject:setLocalScale(scale, scale, scale)
	self.animator.enabled = enabled
end

function BattleNumberComp:setColorType(colorType)
	self.colorType = colorType
end

function BattleNumberComp:getColorType()
	return self.colorType
end

function BattleNumberComp:getDuration()
	return self.time
end

function BattleNumberComp:tick(dt)
	self.time = self.time - dt
end

return BattleNumberComp