Module:Locations

From Candypedia

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

-- Module:Locations
local p = {}

p.groups = {
  {
    name = "Schools",
    list = {
      "Roseville Elementary School",
      "Roseville Middle School",
      "Roseville High School",
      "Roseville High School#Auditorium|<small>Auditorium</small>",
      "Roseville High School#Bus stop|<small>Bus stop</small>",
      "Roseville High School#Cafeteria|<small>Cafeteria</small>",
      "Roseville High School#Gymnasium|<small>Gymnasium</small>",
      "Roseville High School#Library|<small>Library</small>",
      "Roseville High School#Oval|<small>Oval</small>"
    }
  },
  {
    name = "Homes",
    list = {
      "Mike's house","Lucy's house","Paulo's house","Daisy's house",
      "David's house","Augustus's house","Abbey's house","Rachel's house",
      "Sandy's house","Tess's house"
    }
  },
  {
    name = "Businesses",
    list = {
      "Airport","Aquarium","Bowling alley","Burger-Tron","Carnival",
      "Convention center","Drive-in theater","Maraschino mall",
      "Modeling agency","Psychiatrist's office","Roseville cinema",
      "Roseville shopping mall"
    }
  },
  {
    name = "Concepts",
    list = {
      "Blasto","Roseville High Hornets","SwordsVale"
    }
  },
  {
    name = "Other locations",
    list = {
      "Abandoned warehouse rooftop","Abbey's childhood house",
      "Alejandro's apartment","Cinder Station area",
      "East Rutledge High School","Hospital","Maraschino City",
      "Matt's aunt's beachhouse","Museum",
      "Neighborhood sidewalks and streets","Northern Highway",
      "Park","Prom Venue","Silvershore Islands"
    }
  }
}

function p.renderNav(frame)
  local args = {
    "{{Navbox",
    "| name      = Locations",
    "| title     = Locations and concepts",
    "| listclass = hlist",
    "| state     = " .. (frame.args.state or "autocollapse")
  }

  for i, grp in ipairs(p.groups) do
    table.insert(args, "| group" .. i .. " = " .. grp.name)
    local items = {}

    for _, entry in ipairs(grp.list) do
      -- Use ** for anything with a section (#), otherwise *
      local star = entry:find("#") and "** " or "* "
      local target, label
      if entry:find("|") then
        local parts = mw.text.split(entry, "|", true)
        target = parts[1]
        label  = parts[2] or parts[1]
      else
        target = entry
        label  = entry
      end
      table.insert(items, star .. "[[" .. target .. "|" .. label .. "]]")
    end

    table.insert(args,
      "| list" .. i .. " =\n" .. table.concat(items, "\n")
    )
  end

  table.insert(args, "}}")
  return frame:preprocess(table.concat(args, "\n"))
end

function p.renderList(frame)
  local out = {""}

  for _, grp in ipairs(p.groups) do
    table.insert(out, "== " .. grp.name .. " ==\n")
    table.insert(out, '<div style="column-count:3; column-gap:2em;">\n')
    for _, entry in ipairs(grp.list) do
      local target, label
      if entry:find("|") then
        local parts = mw.text.split(entry, "|", true)
        target = parts[1]
        label  = parts[2] or parts[1]
      else
        target = entry
        label  = entry
      end
      table.insert(out, "* [[" .. target .. "|" .. label .. "]]\n")
    end
    table.insert(out, "</div>\n")
  end

  return table.concat(out, "\n")
end

return p