class 'ToolInfoBase'

function ToolInfoBase:__init(toolName)
	assert(toolName)

	self.name		 = toolName
	self.dragObject	 = nil
	self.invIconPath = nil
	self.wndIconPath = nil

	self.additional_info = {}
	self.bTempMarker	 = false

	-- self.sceneData = {}
	-- self.sceneData.applyTargets = nil

	self.additional_info.global_targets	= getToolGlobalTargets(toolName)
	self.additional_info.collection		= getCollectionTools(toolName)
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- SETTERS --------------------------------------------------------------------
-------------------------------------------------------------------------------

function ToolInfoBase:setInvIconPath(path)
	self.invIconPath = path
end
-------------------------------------------------------------------------------

function ToolInfoBase:setWndIconPath(path)
	self.wndIconPath = path
end
-------------------------------------------------------------------------------

function ToolInfoBase:setCollectionOwner(bCollectionOwner)
	self.additional_info.collection_owner = bCollectionOwner
end
-------------------------------------------------------------------------------

function ToolInfoBase:tempMarker()
	self.bTempMarker = true
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- GETTERS --------------------------------------------------------------------
-------------------------------------------------------------------------------

function ToolInfoBase:getName()
	return self.name
end
-------------------------------------------------------------------------------

function ToolInfoBase:getCollection()
	return self.additional_info.collection
end
-------------------------------------------------------------------------------

function ToolInfoBase:isCollectionOwner()
	return self.bCollectionOwner
end
-------------------------------------------------------------------------------

function ToolInfoBase:getDragObject()
	return self.dragObject
end
-------------------------------------------------------------------------------

function ToolInfoBase:getHintText()
	local textKey = 'TOOL_HINT_'..string.upper(self.name)
	return StringManager:getString( textKey )
end
-------------------------------------------------------------------------------

function ToolInfoBase:getInfoText()
	local textKey = 'TOOL_INFO_'..string.upper(self.name)
	return StringManager:getString( textKey )
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- CREATE ENTITIES METHODS ----------------------------------------------------
-------------------------------------------------------------------------------

function ToolInfoBase:createToolEntity()
	local entityName = self.name..TOOL_INVENTORY_SUFFIX
	local entity	 = CreateSpriteEntity(self.invIconPath)

	entity:setName	(entityName)
	entity:setXY	(0, 0)
	entity:setRespondable(false)

	if not entity.properties then
		entity.properties = {}
	end
	
	if decorateToolSprite then
		decorateToolSprite(self.name, entity, false)
	end
		
	if self.bTempMarker then
		self:createTempMarker(entity)
	end
	
	return entity
end
-------------------------------------------------------------------------------

function ToolInfoBase:createToolShadowEntity()
	local entityName = self.name..TOOL_SHADOW_SUFFIX
	local entity	 = CreateSpriteEntity(self.invIconPath)

	entity:setName	(entityName)
	entity:setColor	(1, 1, 1, 0.4)
	entity:setXY	(0, 0)
	entity:setRespondable(false)

	return entity
end
-------------------------------------------------------------------------------

function ToolInfoBase:createInfoIconEntity()
	local entityName = self.name..TOOL_WINDOW_SUFFIX
	local entity	 = CreateSpriteEntityInstant(self.wndIconPath)

	entity:setName	(entityName)
	entity:setOrder	(2)
	entity:setXY	(0, 0)
	entity:setRespondable(false)
	
	if decorateToolSprite then
		decorateToolSprite(self.name, entity, true)
	end
	
	return entity
end
-------------------------------------------------------------------------------

function ToolInfoBase:createTempMarker(parentEntity)
	local markerName = string.format('%s%s_tmp_mark', self.name, TOOL_INVENTORY_SUFFIX)
	local marker	 = CreateSpriteEntity('')

	marker:setName			(markerName)
	marker:attachTo			(parentEntity)
	marker:setColor			(1, 0, 0, 1)
	marker:setXY			(-32, -32)
	marker:setAnimationSize	(10, 10)
	marker:setRespondable	(false)

	WriteWarning("Temporaty tool mark created for " .. self.name)
end
-------------------------------------------------------------------------------

function ToolInfoBase:createDragObject(gameScene, onTake, onDrop, onClick)
	assert(not self.dragObject)
	
	local toolEntity = self:createToolEntity()
	local dragObject = DragObjectBase(gameScene, toolEntity)

	dragObject:setDraggingOffset(Vector2f(0, 0))
	dragObject:setStickyDrag	(true)
	dragObject:setCallback		('afterTake',	onTake)
	dragObject:setCallback		('onDrop',		onDrop)
	dragObject:setCallback		('onDragClick',	onClick)

	self.dragObject = dragObject
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- HELPERS --------------------------------------------------------------------
-------------------------------------------------------------------------------

function ToolInfoBase:isCollection()
	return self.additional_info.collection ~= nil
end
-------------------------------------------------------------------------------

function ToolInfoBase:hasTarget(targetName, sceneName)
	if self.target_name then
		if type(self.target_name) == 'string' then
			return (self.target_name == targetName) and (self.target_scene == sceneName)
		end

		for index, theTargetName in pairs(self.target_name) do
			if (theTargetName == targetName) and (self.target_scene == sceneName) then
				return true, index
			end
		end
	end

	return false
end
-------------------------------------------------------------------------------

function ToolInfoBase:copyApplyData(sourceToolInfo)
	self.target_name	= self.target_name or sourceToolInfo.target_name
	self.target_scene	= self.target_scene or sourceToolInfo.target_scene
	self.once_apply		= self.once_apply or sourceToolInfo.once_apply
	self.on_apply		= self.on_apply or sourceToolInfo.on_apply

	self.additional_info.local_targets_applied = self.additional_info.local_targets_applied or sourceToolInfo.additional_info.local_targets_applied
end
-------------------------------------------------------------------------------