FANDOM


-- starshipcodes module
-- inside: [[Category:Modules]] using this line once...
-- has all the functions that will operate on/about starships
 
-- <pre>
 
local p = {}
local getargs = require('Dev:Arguments').getArgs
local utils = require('Module:Utilities')
local glbls = require('Module:Globals')
local blnks = require('Module:BlankCommons')
local comns = require('Module:CommonCodes')
 
glbls.sorc = 's'
glbls.typename = 'Module:Starshipcodes/'
glbls.filename = 'data'
glbls.keysLoaded = false
glbls.keys = {}
glbls.data = {}
glbls.args = {'junk',}
glbls.starship = 'starsh'
glbls.dumpGLBL = 'TEST-dumpGLBL'
 
function p.hello()
    return 'Hello, world!'
end
 
local function mkOKitems()
    local items = {}
    for k,v in pairs(blnks.ship()) do
        if utils.isSimple(v) then
            --items[#items+1]=k
            items[k]=k
        end
    end
    return items
end
 
local function mkTBLitems()
    local items = {}
    for k,v in pairs(blnks.ship()) do
        if type(v)=='table' then
            --items[#items+1]=k
            items[k]=k
        end
    end
    return items
end
 
function p._main(frame)
    -- this cleans up outside calls for args
    local a
    a = utils.tableShallowCopy(getargs(frame))
    if #a == 0 then return false end
    glbls.args = a
    return true
end
function p.rewrap(frame)
    local a = {}
    if not p._main(frame) then return false end
    local numargs = #glbls.args
    a[1] = 's'
    for i=1,numargs do a[i+1]=glbls.args[i] end
    return true,a
    --mkordered
--    return utils.dumpSimpleList(a,false,false,true,false)
end
 
 
function p.main(frame)
    local ok,a
    local retval='main-fail'
    ok,a = p.rewrap(frame)
    if ok then retval=comns.main(a) end
    return retval
end
function p.codename(frame)
    local ok,a
    local retval='codename-fail'
    ok,a = p.rewrap(frame)
    if ok then retval=comns.makeIGPTfromKey(a) end
    return retval
end
 
local function getItemfromKey(key,item)
    local ok,a
    local retval='getItem-fail'
    local fakeframe = {key,item}
    ok,a = p.rewrap(fakeframe)
    if ok then retval=comns.getItemfromKey(a) end
    return retval
end
local function getSkillItemfromKey(key,sknum,item,skupg)
    local ok,a
    local retval='getSkillItem-fail'
    local fakeframe = {key,sknum,item,skupg}
    ok,a = p.rewrap(fakeframe)
    if ok then retval=comns.SkFt(a) end
    return retval
end
 
 
--  how to pass TABLES rather than strings like for skills...
--  how to pass TABLES rather than strings like for skills...
--  how to pass TABLES rather than strings like for skills...
--  how to pass TABLES rather than strings like for skills...
--  how to pass TABLES rather than strings like for skills...
 
 
local function getTablefromKey(k,tblNm)
    local fake = {}
    local retval='getTable-fail'
    local retTBL
    fake[1]='s'
    fake[2]=tostring(k)
    fake[3]=tostring(tblNm)
    --fake[3]='skills'
    retval=comns.passTBL(fake)
--    retTBL = utils.JSONdecodeString2Table(retval)
    glbls.data = utils.JSONdecodeString2Table(retval)
    return retval
end
 
local function dumpTBLs(key)
    local retval,okTables,tmpTBL
    local retStr,tmpSTR1,tmpSTR2
    okTables = mkTBLitems()  -- ANTI utils.isSimple()
    retStr = ''
    for k,v in pairs(okTables) do
        -- need magic happening...
        tmpSTR1 = 'Table-'..tostring(k)..' = '
        tmpTBL = getTablefromKey(key,v)
        tmpSTR2 = utils.dumpTableSorted(tmpTBL)
        retStr = retStr..tmpSTR1..tmpSTR2..'\n'
    end
end
 
function p.showTBLs(frame)
    local ok,a
    local retval='showTBLs-fail'
    ok,a = p.rewrap(frame)
    if ok then retval=dumpTBLs(glbls.args[1]) end
    return retval
end
 
function p.skills(frame)
    local ok,a
    local retval='skills-fail'
    ok,a = p.rewrap(frame)
    a[#a+1]='skills'
    if ok then retval=comns.passTBL(a) end
    return retval
end
 
 
 
 
local function dumpInfobox(key)
    local retval,okItems,fk
    local retStr,tmpSTR1,tmpSTR2
    local fakeframe = {}
    okItems = mkOKitems()  -- only utils.isSimple()
    retStr = ''
    for k,v in pairs(okItems) do
        tmpSTR1 = '|'..tostring(k)..' = '
        tmpSTR2 = getItemfromKey(key,v)
        retStr = retStr..tmpSTR1..tmpSTR2..'\n'
    end
    -- all starships have 3 skills, unlike crew who some-have-only-2...
    for i=1,3 do
        for _,nm in ipairs({'skill','color','cost','desc',}) do
            local nmi = nm..tostring(i)
            tmpSTR1 = '|'..nmi..' = '
            tmpSTR2 = getSkillItemfromKey(key,i,nm,1)
            retStr = retStr..tmpSTR1..tmpSTR2..'\n'
        end
    end
    return retStr
end
 
--function p.dumpInfobox(frame)
--    return dumpInfobox('SGZ')
--end
 
 
-- should test/continue this...
 
 
-- VERY INELEGANT SOLUTION to swapping templates based on input-requested ??
--  see the mini-fcn-calls below the main-fcn here for pass-back globals...  sigh...
--function p.mkInfobox(frame)
function mkInfobox(frame)
    local hero,urps
    local igpt,key
--    local retStr = '{{infobox character\n'
    local retStr = '{{infobox ' ..glbls.IB_type.. '\n'
    -- using side-effect of global populate of crewHero...  ick...
    igpt = p.codename(frame)
    key = glbls.args[1]
-- checking-for-nil is fine for externally-facing-fcns, imo...
--    if ( type(igpt) ~= 'nil' ) then
    if ( type(igpt) ~= 'nil' ) and ( igpt ~= '' ) then
-- --------    if ( p.codename(frame) ~= '' ) then
        hero = glbls.starship
        --urps = dumpInfobox(hero)
        urps = dumpInfobox(key)
    	if glbls.ERROR_URPTF then
    	    return urps
	    else
	        retStr = retStr .. urps
            retStr = retStr .. '| igpt = ' ..igpt.. '\n'
            retStr = retStr .. '}}\n'
        end
    else
        retStr = 'NO JOY on igpt...  check input data...\n'
    end
    return retStr
end
-- these SHOULD be parsed upon the getargs[0] element (calling-name)...
local function chooseInfobox(word,frame)
    if word == 'mkInfobox' then glbls.IB_type = 'starship' end
    if word == 'mkMiniInfobox' then glbls.IB_type = ' ' end
    if word == 'mkLevelInfobox' then glbls.IB_type = 'starship2' end
 
    return mkInfobox(frame)
end
 
function p.mkInfobox(frame)
    return chooseInfobox('mkInfobox',frame)
end
 
function p.doInfobox(frame)
    return frame:preprocess(p.mkInfobox(frame))
end
 
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.