Module:Research

local research = {}

-- Load modules local iter = require("Module:Functional").iter

local data = require("Module:Data") local item = require("Module:Item")

local CargoUtils = require("Module:CargoUtils") local DurationConverter = require("Module:DurationConverter")

-- Research-related constants local RARITIES = table.concat(iter(data.RARITY_COLORS):keys:totable, ',')

-- Represents a research subject in the game. local Research = data.Entity:subclass("Research") research.Research = Research

Research.static.ATTRIBUTE_TABLE = CargoUtils.CargoTable("Research",	{		["name"] = { "String", { mandatory = true }, { "NOT NULL" } },		["image"] = { "File", { mandatory = true }, { "NOT NULL" } },		["rarity"] = { "String", { mandatory = true, ["allowed values"] = RARITIES }, { "NOT NULL" } },		["designation"] = { "String", { ["allowed values"] = "Arms Lab,Tech Lab,Ship Lab,None" } },		["is_auto"] = { "Boolean" },		["xp"] = { "Integer" },		["prereq_items"] = { "List of Page" },		["prereq_researches"] = { "List  of Page" },		["prereq_blueprints"] = { "List  of Page" },		["research_helium_3"] = { "Integer" },		["research_mineral_ore"] = { "Integer" },		["research_antimatter"] = { "Integer" },		["research_seconds"] = { "Integer" },		["description"] = { "Wikitext" },	},	{ "_pageName" },	{		["prereq_items"] = { "Item", "_pageName" },		["prereq_researches"] = { "Research", "_pageName" },		["prereq_blueprints"] = { "Blueprint", "_pageName" }, })

-- Static methods -- -- Returns a new Research instance with properties according to the record stored in the given page. function Research.static:fromPageName(fullpagename) assert(type(fullpagename) == type(""), "`fullpagename` must be a string") local query_args = {where = string.format("_pageName = '%s'", fullpagename)} return Research(self.ATTRIBUTE_TABLE:query(query_args, true)[1]) end

-- Module call from Template:Research Definition function research.declareTable( frame ) return Research.ATTRIBUTE_TABLE:declare(frame) end

-- Module call from Template:Research Definition function research.define( frame ) local args = require("Module:Args").getCleanArgs

if (args.prereq_items) then args.prereq_items = table.concat(iter(mw.text.split(args.prereq_items, '%s*,%s*')):map(function (e) return "Item:" .. e end):totable, ',') end if (args.prereq_researches) then args.prereq_researches = table.concat(iter(mw.text.split(args.prereq_researches, '%s*,%s*')):map(function (e) return "Research:" .. e end):totable, ',') end if (args.prereq_blueprints) then args.prereq_blueprints = table.concat(iter(mw.text.split(args.prereq_blueprints, '%s*,%s*')):map(function (e) return "Blueprint:" .. e end):totable, ',') end if (args.research_time) then args.research_seconds = tostring(DurationConverter.durationToSeconds(args.research_time)) args.research_time = nil end local research_to_store = Research(args) local store = research_to_store:storeToTable(Research.ATTRIBUTE_TABLE) return store .. tostring(research_to_store:generateInfobox) end

-- Module call from Template:Research Infobox function research.generateInfobox( frame ) local args = require("Module:Args").getCleanArgs local fullpagename = "Research:" .. assert(args.full_name, "Missing argument `full_name`") local general_only = args.general_only local no_categories = args.no_categories return Research:fromPageName(fullpagename):generateInfobox(general_only, no_categories) end

return research