Module:Formatting

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

local Formatting = { _image_template = "", _image_sized_template = "", _no_image = "Catbomb.png", _no_image_size = "300px", _resource_template = "${icon} ${value}", _detailed_aircraft_template = "${total}\n(${slots})", _stat_with_max_template = "${stat} (${max})", _remodel_level_and_cost_template = "Level ${level} (${cost}${blueprint})", _simple_link = "${link}${section}", _aliased_link = "${text}" }

function Formatting:seconds_to_hms(seconds) return format{"${hours:2}:${minutes:2}:${seconds:2}", hours = math.floor(seconds / 3600), minutes = math.floor(seconds / 60) % 60, seconds = seconds % 60 } end

function Formatting:format_image(name, size) if name == nil then return format{self._image_sized_template, image = self._no_image, size = size or self._no_image_size} elseif size then return format{self._image_sized_template, image = name, size = size} else return format{self._image_template, image = name} end end

function Formatting:create_formatter(lookup, nil_value) return function(self, stat) if stat == nil then return nil_value or "??" end local result = lookup[stat] if result == nil then return stat else return result end end end

function Formatting:format_resources(fuel, ammo, steel, bauxite) local strings = {} if fuel then table.insert(strings, format{self._resource_template, icon = ResourceIcons.fuel, value = fuel}) elseif ammo then table.insert(strings, format{self._resource_template, icon = ResourceIcons.ammo, value = ammo}) elseif steel then table.insert(strings, format{self._resource_template, icon = ResourceIcons.steel, value = steel}) elseif bauxite then table.insert(strings, format{self._resource_template, icon = ResourceIcons.bauxite, value = bauxite}) end return table.concat(strings, " ") end

function Formatting:format_remodel_level_and_cost(remodel_level, resource_cost, blueprint) return format{self._remodel_level_and_cost_template, level = remodel_level, cost = resource_cost, blueprint = Formatting:format_blueprint_requirement(blueprint, false, " ")} end

function Formatting:format_blueprint_requirement(blueprint, force, prefix) if force or blueprint then return format{prefix and (prefix .. self._resource_template) or self._resource_template, icon = format_image(ResourceIcons.blueprint, "36px"), value = blueprint and "✓" or "✗"} end return "" end

function Formatting:format_equipment_icon(icon) if not icon then return "Xx_c.png" end return icon end

function Formatting:format_slot_size(size) if size == nil then return "??" elseif size == false then return "-" else return size end end

function Formatting:format_detailed_aircraft(total, slots) if not total then return self:format_stat(total) else slot_summary = table.concat(slots, ",") return format{self._detailed_aircraft_template, total = total, slots = slot_summary} end end

function Formatting:format_stat_with_max(stat, max) if max == false then return self:format_stat(stat) else return format{self._stat_with_max_template, stat = self:format_stat(stat), max = self:format_stat(max)} end end

function Formatting:format_link(link, text, section) if section then section = "#" .. section else section = "" end if text then return format{self._aliased_link, link = link, text = text, section = section} else return format{self._simple_link, link = link, section = section} end end

Formatting.format_stat = Formatting:create_formatter({	[false] = "",	})

Formatting.format_speed = Formatting:create_formatter({	[5] = "Slow",	[10] = "Fast",	})

Formatting.format_range = Formatting:create_formatter({	[0] = "Very Short",	[1] = "Short",	[2] = "Medium",	[3] = "Long",	[4] = "Very Long",	})

Formatting.format_ship_rarity = Formatting:create_formatter({	[1] = "Very Common",	[2] = "Common",	[3] = "Uncommon",	[4] = "Rare",	[5] = "Very Rare",	[6] = "Holo",	[7] = "S Holo",	[8] = "SS Holo",	[-1] = "Abyssal",	[-2] = "Elite",	[-3] = "Flagship",	[-4] = "Kai",	[-5] = "Kai Elite",	[-6] = "Kai Flagship",	[-7] = "Late Model",	float = "Floating Fortress",	demon = "Demon",	princess = "Princess",	war_demon = "War Demon",	war_princess = "War Princess",	})

Formatting.format_ship_type = Formatting:create_formatter({	[1] = "Coastal Defence Ship",	[2] = "Destroyer",	[3] = "Light Cruiser",	[4] = "Torpedo Cruiser",	[5] = "Heavy Cruiser",	[6] = "Aviation Cruiser",	[7] = "Light Carrier",	[8] = "Battleship",	[9] = "Battleship",	[10] = "Aviation Battleship",	[11] = "Standard Carrier",	[12] = "Super Dreadnought",	[13] = "Submarine",	[14] = "Aircraft Carrying Submarine",	[15] = "Replenishment Oiler",	[16] = "Seaplane Tender",	[17] = "Amphibious Assault Ship",	[18] = "Armored Carrier",	[19] = "Repair Ship",	[20] = "Submarine Tender",	[21] = "Training Cruiser",	})

Formatting.format_equipment_type = Formatting:create_formatter({	[1] = "Small Caliber Main Gun",	[2] = "Medium Caliber Main Gun",	[3] = "Large Caliber Main Gun",	[4] = "Secondary Gun",	[5] = "Torpedo",	[6] = "Carrier-based Fighter Aircraft",	[7] = "Carrier-based Dive Bomber",	[8] = "Carrier-based Torpedo Bomber",	[9] = "Carrier-based Reconnaissance Aircraft",	[10] = "Reconnaissance Seaplane",	[11] = "Seaplane Bomber",	[12] = "Small Radar",	[13] = "Large Radar",	[14] = "Sonar",	[15] = "Depth Charge",	[16] = "Extra Armor",	[17] = "Engine Improvement",	[18] = "Anti-Aircraft Shell",	[19] = "Armor Piercing Shell",	[20] = "VT Fuze",	[21] = "Anti-Aircraft Machine Gun",	[22] = "Midget Submarine",	[23] = "Damage Control Personnel",	[24] = "Landing Craft",	[25] = "Autogyro",	[26] = "Anti-submarine Patrol Aircraft",	[27] = "Extra Armor (Medium)",	[28] = "Extra Armor (Large)",	[29] = "Searchlight",	[30] = "Supply Transport Container", [31] = "Ship Repair Facility", [32] = "Submarine Torpedo", [33] = "Star Shell", [34] = "Command Facility", [35] = "Aviation Personnel", [36] = "Anti-Aircraft Fire Director", [37] = "Anti-Ground Artillery", [38] = "Large Caliber Main Gun (II)", })

Formatting.format_equipment_icon = Formatting:create_formatter({	[false] = "Xx_c.png",	[1] = "RedGunLight.png",	[2] = "RedGunMedium.png",	[3] = "RedGunHeavy.png",	[4] = "YellowGun.png",	[5] = "Torpedo.png",	[6] = "GreenPlane.png",	[7] = "RedPlane.png",	[8] = "BluePlane.png",	[9] = "YellowPlane.png",	[10] = "Seaplane.png",	[11] = "Radar.png",	[12] = "GreenAmmo.png",	[13] = "RedAmmo.png",	[14] = "EmergencyRepair.png",	[15] = "GreenGunMG.png",	[16] = "GreenGunDP.png",	[17] = "DepthCharge.png",	[18] = "Sonar.png",	[19] = "Turbine.png",	[20] = "LandingCraft.png",	[21] = "Heli.png",	[22] = "Subplane.png",	[23] = "Expansion Bulge (Medium).png",	[24] = "Searchlight.png",	[25] = "Drum.png",	[26] = "Facility.png",	[27] = "FlareIcon.png",	[28] = "Cf_c.png",	[29] = "Ap_c.png",	[30] = "Aafd_c.png",	[31] = "Agat_c.png",	})

Formatting.format_equipment_rarity = Formatting:create_formatter({	[0] = "Common",	[1] = "Rare",	[2] = "Holo",	[3] = "S Holo",	[4] = "SS Holo",	[5] = "SS Holo",	})

return Formatting