Module:ShipCardKai

Revision as of 08:40, 22 August 2015 by com>Ckwng

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

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

local format = require("Module:StringInterpolation").format

local ShipCardKai = {
	_card_size = "218x300px",
	_battle_card_size = "160x40px",
	_battle_card_layers = {
		takoyaki = {image = "Hell plane 2.png", top = "5px", left = "50px", size = "30x30px"},
		hell = {image = "Hell plane 2.png", top = "5px", left = "50px", size = "30x30px"},
		hell_r = {image = "Hell plane 2.png", top = "5px", left = "50px", size = "30x30px"},
		hell_l1 = {image = "Hell plane 2.png", top = "9px", left = "44px", size = "30x30px"},
		hell_r1 = {image = "Hell plane 2.png", top = "9px", left = "109px", size = "30x30px"},
		hell_offset_l1 = {image = "Hell plane 2.png", top = "9px", left = "44px", size = "30x30px"},
		hell_offset_r1 = {image = "Hell plane 2.png", top = "9px", left = "109px", size = "30x30px"},
		flagship = {image = "Flagship battle card icon.png", top = "3px", left = "139px"},
		revenge_kai_l2 = {image = "Abyssal Revenge Torpedo Bomber Kai.png", top = "0px", left = "60px", size = "35x44px"},
		revenge_kai_r2 = {image = "Abyssal Revenge Torpedo Bomber Kai.png", top = "0px", left = "125px", size = "35x44px"},
		revenge_kai_offset_l2 = {image = "Abyssal Revenge Torpedo Bomber Kai.png", top = "0px", left = "60px", size = "35x44px"},
		revenge_kai_offset_r2 = {image = "Abyssal Revenge Torpedo Bomber Kai.png", top = "0px", left = "125px", size = "35x44px"},
		hell_kai_l1 = {image = "Abyssal Hell Dive Bomber Kai.png", top = "5px", left = "39px", size = "35x35px"},
		hell_kai_r1 = {image = "Abyssal Hell Dive Bomber Kai.png", top = "5px", left = "104px", size = "35x35px"},
		hell_kai_offset_l1 = {image = "Abyssal Hell Dive Bomber Kai.png", top = "5px", left = "39px", size = "35x35px"},
		hell_kai_offset_r1 = {image = "Abyssal Hell Dive Bomber Kai.png", top = "5px", left = "104px", size = "35x35px"},
		attack_seaplane_kai_r = {image = "Abyssal Attack Seaplane Kai.png", top = "0px", left = "120px", size = "35x35px"},
	},
	_battle_card_wrapper = [[<span style="display: inline-block; position: relative;">${layers}</span>]],
	_image_layer = [[<span style="position: absolute; top: ${top}; left: ${left}; line-height: 0px;">${image}</span>]],
}

function ShipCardKai:card(ship, args)
	if not args then
		args = ship
		ship = args.ship
	end
	return Formatting:format_image{args.damaged and ship:card_damaged() or ship:card(), size = args.size or self._card_size, link = args.link, caption = args.caption}
end

function ShipCardKai:Card(args)
	local ship = self:create_ship(args)
	return self:card(ship, args)
end

function ShipCardKai:battle_card(ship, args)
	if not args then
		args = ship
		ship = args.ship
	end
	local image = Formatting:format_image{args.damaged and ship:battle_card_damaged() or ship:battle_card(), size = args.size or self._battle_card_size, link = args.link, caption = args.caption}
	local ship_layers = ship:battle_card_layers()
	if ship_layers or args.flagship then
		local layers = {image}
		if ship_layers then
			for _, layer in ipairs(ship_layers) do
				self:_add_layer(layers, self._battle_card_layers[layer])
			end
		end
		if args.flagship then
			self:_add_layer(layers, self._battle_card_layers.flagship)
		end
		image = format{self._battle_card_wrapper, layers = table.concat(layers)}
	end
	return image
end

function ShipCardKai:_add_layer(layers, layer)
	table.insert(layers, format{self._image_layer, image = Formatting:format_image{layer.image, caption = layer.caption, size = layer.size}, top = layer.top, left = layer.left})
end

function ShipCardKai:BattleCard(args)
	local ship = self:create_ship(args)
	return self:battle_card(ship, args)
end

function ShipCardKai:create_ship(args)
	if args.name then
		return Ship(args.name, args.model)
	else
		return Ship(args[1])
	end
end

return ShipCardKai