Module:Locations

From Candypedia
Revision as of 23:31, 23 April 2025 by SuitCase (talk | contribs) (Modularising locations too)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

-- Module:Locations
local p = {}

-- 1) Define your ordered groups & items
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"
    }
  }
}

-- 2a) Render the navbox (with proper re-parsing)
function p.renderNav(frame)
  local args = {
    "{{Navbox",
    "| name      = Locations and concepts",
    "| 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
      -- allow piped sublinks
      if entry:find("|") then
        local target, label = mw.text.split(entry, "|", true)
        table.insert(items, "* [[" .. target .. "|" .. label .. "]]")
      else
        table.insert(items, "* [[" .. entry .. "]]")
      end
    end
    table.insert(args, "| list" .. i .. " =\n" .. table.concat(items, "\n"))
  end
  table.insert(args, "}}")
  return frame:preprocess(table.concat(args, "\n"))
end

-- 2b) Render a plain “List of locations and concepts” page
function p.renderList(frame)
  local out = {"= List of locations and concepts =\n"}
  for _, grp in ipairs(p.groups) do
    table.insert(out, "== " .. grp.name .. " ==\n")
    table.insert(out, "<div style=\"column-count:2; column-gap:2em;\">\n")
    for _, entry in ipairs(grp.list) do
      if entry:find("|") then
        local target, label = mw.text.split(entry, "|", true)
        table.insert(out, "* [[" .. target .. "|" .. label .. "]]\n")
      else
        table.insert(out, "* [[" .. entry .. "]]\n")
      end
    end
    table.insert(out, "</div>\n")
  end
  return table.concat(out, "\n")
end

return p