Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
[checked revision][checked revision]
(Created page with "local Role = require('Module:Role2') local CompoundRole = require('Module:CompoundRole') local h = {} local p = {} function p.castField(v, v_type) if v_type == 'role' then...")
 
Line 1: Line 1:
local Role = require('Module:Role2')
+
local Champion = require('Module:Champion')
local CompoundRole = require('Module:CompoundRole')
+
local ChampionList = require('Module:ChampionList')
  +
local Country = require('Module:Country')
  +
local CountryList = require('Module:CountryList')
  +
local League = require('Module:League')
  +
local LeagueList = require('Module:LeagueList')
  +
local Region = require('Module:Region')
  +
local Role = require('Module:Role')
  +
local RoleList = require('Module:RoleList')
 
local h = {}
 
local h = {}
 
local p = {}
 
local p = {}
  +
  +
p.objectTypes = {
  +
champion = Champion,
  +
championlist = ChampionList,
  +
country = Country,
  +
countrylist = CountryList,
  +
league = League,
  +
leaguelist = LeagueList,
  +
region = Region,
  +
role = Role,
  +
rolelist = RoleList,
  +
}
   
 
function p.castField(v, v_type)
 
function p.castField(v, v_type)
if v_type == 'role' then
+
if p.objectTypes[v_type] then
return Role(v)
+
return p.objectTypes[v_type](v)
elseif v_type == 'compoundrole' then
 
return CompoundRole(v)
 
 
end
 
end
 
error('Unrecognized Cargo value casting type')
 
error('Unrecognized Cargo value casting type')
  +
end
  +
  +
function p.castComplexTypes(row, info)
  +
local objType = info.type
  +
local args = info.args
  +
local opts = {}
  +
for k, v in pairs(args) do
  +
opts[k] = row[v]
  +
end
  +
if objType == 'rolelist' then
  +
return RoleList(row[args[1]], opts)
  +
end
  +
error(('Unrecognized Cargo complex value casting type of %s'):format(objType))
 
end
 
end
   

Revision as of 16:33, 18 August 2020

To edit the documentation or categories for this module, click here.


local Champion = require('Module:Champion')
local ChampionList = require('Module:ChampionList')
local Country = require('Module:Country')
local CountryList = require('Module:CountryList')
local League = require('Module:League')
local LeagueList = require('Module:LeagueList')
local Region = require('Module:Region')
local Role = require('Module:Role')
local RoleList = require('Module:RoleList')
local h = {}
local p = {}

p.objectTypes = {
	champion = Champion,
	championlist = ChampionList,
	country = Country,
	countrylist = CountryList,
	league = League,
	leaguelist = LeagueList,
	region = Region,
	role = Role,
	rolelist = RoleList,
}

function p.castField(v, v_type)
	if p.objectTypes[v_type] then
		return p.objectTypes[v_type](v)
	end
	error('Unrecognized Cargo value casting type')
end

function p.castComplexTypes(row, info)
	local objType = info.type
	local args = info.args
	local opts = {}
	for k, v in pairs(args) do
		opts[k] = row[v]
	end
	if objType == 'rolelist' then
		return RoleList(row[args[1]], opts)
	end
	error(('Unrecognized Cargo complex value casting type of %s'):format(objType))
end

return p