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

Difference between revisions of "Module:ShipCardKai"

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
m (40 revisions imported)
 
(28 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local Ship = require('Module:Ship')
 
 
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
 +
local ShipAsset = require('Module:ShipAsset')
  
local format = require("Module:StringInterpolation").format
+
local split = require("Module:Core").split
  
local ShipCardKai = {
+
local ShipCardKai = ShipAsset{
 
_card_size = "218x300px",
 
_card_size = "218x300px",
_battle_card_size = "160x40px",
+
_card_size_hd = "327x450px",
_battle_card_layers = {
+
_card_layers = {
takoyaki = {image = "Hell plane 2.png", top = "5px", left = "50px", size = "30x30px"},
+
status_expedition = {image = "Card Status Expedition.png", style = {top = "229px", left = "133px"}},
hell = {image = "Hell plane 2.png", top = "5px", left = "50px", size = "30x30px"},
+
status_repair = {image = "Card Status Repair.png", style = {top = "228px", left = "133px"}},
hell_offset_l1 = {image = "Hell plane 2.png", top = "9px", left = "44px", size = "30x30px"},
+
status_light_damage = {image = "Card Status Light Damage.png", style = {top = "228px", left = "133px"}},
hell_offset_r1 = {image = "Hell plane 2.png", top = "9px", left = "104px", size = "30x30px"},
+
status_medium_damage = {image = "Card Status Medium Damage.png", style = {top = "228px", left = "133px"}},
flagship = {image = "Flagship battle card icon.png", top = "3px", left = "139px"},
+
status_heavy_damage = {image = "Card Status Heavy Damage.png", style = {top = "228px", left = "133px"}},
revenge_kai_offset_l2 = {image = "Abyssal Revenge Torpedo Bomber Kai.png", top = "0px", left = "60px", size = "35x44px"},
+
status_sunk = {image = "Card Status Sunk.png", style = {top = "228px", left = "133px"}},
revenge_kai_offset_r2 = {image = "Abyssal Revenge Torpedo Bomber Kai.png", top = "0px", left = "120px", size = "35x44px"},
+
ring = {image = "Card Marriage Ring.png", style = {top = "260px", left = "180px"}},
hell_kai_offset_l1 = {image = "Abyssal Hell Dive Bomber Kai.png", top = "5px", left = "39px", size = "35x35px"},
+
ring_glow = {image = "Card Marriage Ring Glow.png", style = {top = "254px", left = "170px", opacity = "0.7"}},
hell_kai_offset_r1 = {image = "Abyssal Hell Dive Bomber Kai.png", top = "5px", left = "99px", 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)
+
function ShipCardKai:get_source(ship, args)
if not args then
+
return args.damaged and ship:card_damaged(args.hd) or ship:card(args.hd)
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
 
end
  
function ShipCardKai:battle_card(ship, args)
+
function ShipCardKai:get(ship, args, link)
 
if not args then
 
if not args then
 
args = ship
 
args = ship
 
ship = args.ship
 
ship = args.ship
 +
link = args.link
 +
end
 +
args[1] = self:get_source(ship, args)
 +
if not args.size then
 +
args.size = args.hd and self._card_size_hd or self._card_size
 
end
 
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}
+
args.link = link
local ship_layers = ship:battle_card_layers()
+
local image = Formatting:format_image(args)
if ship_layers or args.flagship then
+
if args.layers or args.grayscale then
local layers = {image}
+
local stack = self:_create_stack(image, args.grayscale)
if ship_layers then
+
if args.layers then
for _, layer in ipairs(ship_layers) do
+
for _, layer in ipairs(split(args.layers)) do
self:_add_layer(layers, self._battle_card_layers[layer])
+
if self._card_layers[layer] then
 +
self:_add_layer(stack, self._card_layers[layer], ship, args, link)
 +
end
 
end
 
end
 
end
 
end
if args.flagship then
+
image = tostring(stack)
self:_add_layer(layers, self._battle_card_layers.flagship)
 
end
 
image = format{self._battle_card_wrapper, layers = table.concat(layers)}
 
 
end
 
end
 
return image
 
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
 
end
  
 
return ShipCardKai
 
return ShipCardKai

Latest revision as of 12:29, 12 May 2021

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

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

local split = require("Module:Core").split

local ShipCardKai = ShipAsset{
	_card_size = "218x300px",
	_card_size_hd = "327x450px",
	_card_layers = {
		status_expedition = {image = "Card Status Expedition.png", style = {top = "229px", left = "133px"}},
		status_repair = {image = "Card Status Repair.png", style = {top = "228px", left = "133px"}},
		status_light_damage = {image = "Card Status Light Damage.png", style = {top = "228px", left = "133px"}},
		status_medium_damage = {image = "Card Status Medium Damage.png", style = {top = "228px", left = "133px"}},
		status_heavy_damage = {image = "Card Status Heavy Damage.png", style = {top = "228px", left = "133px"}},
		status_sunk = {image = "Card Status Sunk.png", style = {top = "228px", left = "133px"}},
		ring = {image = "Card Marriage Ring.png", style = {top = "260px", left = "180px"}},
		ring_glow = {image = "Card Marriage Ring Glow.png", style = {top = "254px", left = "170px", opacity = "0.7"}},
	},
}

function ShipCardKai:get_source(ship, args)
	return args.damaged and ship:card_damaged(args.hd) or ship:card(args.hd)
end

function ShipCardKai:get(ship, args, link)
	if not args then
		args = ship
		ship = args.ship
		link = args.link
	end
	args[1] = self:get_source(ship, args)
	if not args.size then
		args.size = args.hd and self._card_size_hd or self._card_size
	end
	args.link = link
	local image = Formatting:format_image(args)
	if args.layers or args.grayscale then
		local stack = self:_create_stack(image, args.grayscale)
		if args.layers then
			for _, layer in ipairs(split(args.layers)) do
				if self._card_layers[layer] then
					self:_add_layer(stack, self._card_layers[layer], ship, args, link)
				end
			end
		end
		image = tostring(stack)
	end
	return image
end

return ShipCardKai