• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Module:BaseAsset

From Kancolle Wiki
Revision as of 19:23, 20 June 2022 by がか (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:BaseAsset/doc

local BaseData = require('Module:BaseData')
local Formatting = require('Module:Formatting')

local BaseAsset = BaseData{
	-- overflow = "hidden", ['vertical-align'] = "middle"
	_image_wrapper_style = {display = "inline-block", position = "relative"},
	-- ['line-height'] = "0px"
	_image_layer_style = {position = "absolute"},
	_grayscale_style = {filter = "grayscale(100%)", ['-webkit-filter'] = "grayscale(100%)"},
}

function BaseAsset:_add_layer(stack, layer, ship, args, link)
	-- addClass('image-layer')
	stack:node(mw.html.create('span'):css(self._image_layer_style):css(layer.style):wikitext(Formatting:format_image{
	    layer.image,
	    -- caption = layer.caption or args.caption,
	    size = layer.size,
	    link = ""
	}))
end

function BaseAsset:_create_stack(image, grayscale)
	-- :addClass('image-stack')
	local stack = mw.html.create('span'):css(self._image_wrapper_style)
	if grayscale then
		stack:node(mw.html.create('span'):addClass('grayscale-wrapper'):css(self._grayscale_style):wikitext(image))
	else
		stack:wikitext(image)
	end
	return stack
end

function BaseAsset:Asset(args)
	local object = self:create_object(args)
	if args.mode == "source" then
		return self:get_source(object, args) or Formatting:error_span("No asset could be found.")
	elseif args.link then
		if args.link == "nil" then
			return self:get(object, args, nil)
		elseif args.link == "false" then
			return self:get(object, args, false)
		else
			return self:get(object, args, args.link)
		end
	else
		return self:get(object, args, object:link())
	end
end

return BaseAsset