Geyser.Container:objectQuery(objectTable)

Share your scripts and packages with other Mudlet users.
Post Reply
davidwiththenicehat
Posts: 9
Joined: Tue Jul 02, 2019 4:29 pm

Geyser.Container:objectQuery(objectTable)

Post by davidwiththenicehat » Wed Nov 13, 2019 5:48 am

Geyser.Container:objectQuery(objectTable) is a function used to collect geyser object data into multiple tables.
The tables created are: name, type, parentName (Which appears to be parentType), xposition, yposition, width and height.
Usage is
objectTable = geyserObjectName:objectQuery()
objectTable or tabled contained within IE objectTable.name can be looped through to check for data.

The usage example below is using it to redraw all labels in a project that uses GUIframe.

Code: Select all

function tecRedrawLabels()

  tecConfigThemes() --redo themes data. something likely changed

  --Create table to store all geyser objects within GUIframe
  ContainerDataTable = { 
    GUIframe.bottomRightContainer:objectQuery(),
    GUIframe.topLeftContainer:objectQuery(),
    GUIframe.bottomLeftContainer:objectQuery(),
    GUIframe.bottomContainer:objectQuery(),
    GUIframe.bottomRightContainer:objectQuery(),
    GUIframe.topRightContainer:objectQuery(),
    GUIframe.topContainer:objectQuery(),
    GUIframe.topLeftTabs:objectQuery(),
    GUIframe.topRightTabs:objectQuery(),
    GUIframe.bottomLeftTabs:objectQuery(),
    GUIframe.bottomRightTabs:objectQuery() }
    
  --Go through all the tables we created above
  for key,cdt in pairs(ContainerDataTable) do
    for k,v in pairs(cdt.type) do --Check the types of containers
      if v == "label" then --To see if it is a label
        if "map" == cdt.name[k]:match("map") then --if map label is found, skip
          --debugc("Not redrawing map labels.")
        elseif "Compass." == cdt.name[k]:match("Compass.") then
          --debugc("Skip compass label"..cdt.name[k])
        elseif "tab" == cdt.name[k]:match("tab") or "Tab" == cdt.name[k]:match("Tab") then
          setLabelStyleSheet(cdt.name[k],tabsStyle)
          debugc("Apply tabs style sheet to: "..cdt.name[k])
        else --Reapply default style sheets to all other labels.
          setLabelStyleSheet(cdt.name[k], labelsStyle)
          debugc("Apply style sheet to: "..cdt.name[k])
        end
        --debugc("\tTable type: "..v.." key: "..k)
      end --if cdt.type is label
    end --for cdt
  end --for ContainerDataTable
      
  cecho("Don't forget to save your changes with: ")
  cechoLink("<:"..tecSettings.helpHighlightColor..">tecclient save\n", 
  [[tecFileSaveSettings(true)]],
  "Save client settings", true)
  cecho("") --cechoLink does not new line itself.
  
end --function tecRedrawLabels()
Geyser.Container:objectQuery(objectTable) code:

Code: Select all

function Geyser.Container:objectQuery(objectTable)
  --We are addding data to this table each loop.
  --We assume first run if a table is not passed. So we created the table.
  objectTable = objectTable or
    {name={}, type={}, parentName={}, xPos={}, yPos={}
    ,width={}, height={}}
  
  --windowList reference: https://www.mudlet.org/geyser/files/geyser/GeyserContainer.html
  --Loop through all children of this container.
  for k,v in pairs(self.windowList) do
      if k ~= self then --if the key is not this geyser object
    		  objectTable = v:objectQuery(objectTable) --query that object.
      end --end if k not = self check
  end --end for loop pair(self.windowlist)
  
--[[this.object logic can SEEM confusing. It's not.
At this point we have reach the 'bottom' of ourcontainer query.
So the last child with the last alphabetical name.
We insert our object data. Than return it. Meaning this now occurs for the second to
the last geyser object, and so on until we reach the parent that called the query.]]--
  
  --https://wiki.mudlet.org/w/Manual:Lua_Functions#debugc
  --debugc("Geyser.Container:objectQuery: Inserting Object data for: "..self.name)
  
  --Collect this object data.
  --Reference: https://www.mudlet.org/geyser/files/geyser/GeyserContainer.html
  table.insert(objectTable.name, tostring(self.name))
  table.insert(objectTable.type, tostring(self.type))
  table.insert(objectTable.parentName, tostring(self.parent.name))
  table.insert(objectTable.xPos, tostring(self:get_x()))
  table.insert(objectTable.yPos, tostring(self:get_y()))
  table.insert(objectTable.width, tostring(self:get_width()))
  table.insert(objectTable.height, tostring(self:get_height()))

  return objectTable --return the table to the object that called this object
  
end --Geyser.Container:objectQuery(objectTable)

User avatar
Vadi
Posts: 4728
Joined: Sat Mar 14, 2009 3:13 pm

Re: Geyser.Container:objectQuery(objectTable)

Post by Vadi » Wed Nov 13, 2019 6:10 am

Looks cool! But why would you need to recopy Geyser's data into another table, when you already have references to everything? Say for 'GUIframe.bottomRightContainer:objectQuery()' - you already know everything you put into that container.

davidwiththenicehat
Posts: 9
Joined: Tue Jul 02, 2019 4:29 pm

Re: Geyser.Container:objectQuery(objectTable)

Post by davidwiththenicehat » Thu Nov 14, 2019 12:26 am

Because I am using labels to draw my maps I have have something like 320 geyser objects.
Working with bulk objects.

I use GUIframe but I do not know much about it. This allows me to continue to be ignorant on its setup. I did not know the tab names without it.
Working with unknown or dynamic objects.

However my main reason is I would like to make a UI manager with free floating windows. I will want to dynamically track windows. This method creates a data structure for me to track changes.
Dynamic data collection.

Plus it was fun to write.

davidwiththenicehat
Posts: 9
Joined: Tue Jul 02, 2019 4:29 pm

Re: Geyser.Container:objectQuery(objectTable)

Post by davidwiththenicehat » Thu Nov 14, 2019 12:32 am

Can I get the name of a parent object from windowList? I could could do this in reverse order. Allowing people to see the gui structure if they do not know what it is.
Parent.name has been giving me a generic name. If I recall something along the lines of "windowContainer".

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests