Overriding Class Variables

Posted by Xavious on Mon 13 Jul 2015 06:10 PM — 6 posts, 20,887 views.

#0
I'm using mapper.lua to tailor a mapper for my mud. However, some of the default_configs don't apply to my situation. Is there a way for me to override these values somehow to prevent them from being added to the configuration list on the mapper.init() method without modifying the class file?

This has become a concern because my configuration list has become too large to display. I know I could just modify the class file to accomplish what I want, but I'm hoping Lua offers some way to override the class without having to change the class file.
Australia Forum Administrator #1
What class file are you referring to?
#2
mapper.lua

I want to override the default_config table to not include a few pieces.


local default_config = {
  -- assorted colours
  BACKGROUND_COLOUR       = { name = "Background",        colour =  ColourNameToRGB "lightseagreen", },
  ROOM_COLOUR             = { name = "Room",              colour =  ColourNameToRGB "cyan", },
  EXIT_COLOUR             = { name = "Exit",              colour =  ColourNameToRGB "darkgreen", },
  EXIT_COLOUR_UP_DOWN     = { name = "Exit up/down",      colour =  ColourNameToRGB "darkmagenta", },
  EXIT_COLOUR_IN_OUT      = { name = "Exit in/out",       colour =  ColourNameToRGB "#3775E8", },
  UNKNOWN_ROOM_COLOUR     = { name = "Unknown room",      colour =  ColourNameToRGB "#00CACA", },
  MAPPER_NOTE_COLOUR      = { name = "Messages",          colour =  ColourNameToRGB "lightgreen" },
  
  ROOM_NAME_TEXT          = { name = "Room name text",    colour = ColourNameToRGB "#BEF3F1", },
  ROOM_NAME_FILL          = { name = "Room name fill",    colour = ColourNameToRGB "#105653", },
  ROOM_NAME_BORDER        = { name = "Room name box",     colour = ColourNameToRGB "black", },
  
  AREA_NAME_TEXT          = { name = "Area name text",    colour = ColourNameToRGB "#BEF3F1",},
  AREA_NAME_FILL          = { name = "Area name fill",    colour = ColourNameToRGB "#105653", },   
  AREA_NAME_BORDER        = { name = "Area name box",     colour = ColourNameToRGB "black", },
               
  FONT = { name =  get_preferred_font {"Dina",  "Lucida Console",  "Fixedsys", "Courier", "Sylfaen",} ,
           size = 8
         } ,
         
  -- size of map window
  WINDOW = { width = 400, height = 400 },
  
  -- how far from where we are standing to draw (rooms)
  SCAN = { depth = 30 },
  
  -- speedwalk delay
  DELAY = { time = 0.3 },
  
  -- how many seconds to show "recent visit" lines (default 3 minutes)
  LAST_VISIT_TIME = { time = 60 * 3 },  
  
  }
#3
"Exit In/Out" isn't applicable to my mud and I don't intend to use Area either. I could easily change the mapper.lua file, but for the sake of OOP and keeping things self contained, I was hoping I could override the default_config{} table somehow to exclude fields I don't want, rather than making changes to mapper.lua

I wouldn't even bother, but when this config list is too large, it will exclude the color configs from the configuration menu that comes up when you click "*" and I've added a lot of extra room flags.
Amended on Tue 14 Jul 2015 03:20 AM by Xavious
Australia Forum Administrator #4
After (maybe) calling mapper.init, just make the ones you don't want to be nil.

eg.


config.UNKNOWN_ROOM_COLOUR = nil


If they aren't in the config table, they won't be listed.
#5
I added so many items that the colors were being omitted from the window when using the default window height of 400.

Exploring this function in mapper.lua, I realized why it was happening:

local function draw_configuration ()



If the size exceeds the mapper window, it reverts to only displaying the main 4 configurations that are unrelated to color.

I was able to work around this by setting some configuration colors that I wasn't using to nil, like you suggested. Thanks Nick.