Selectors

Selectors

  • editor.parts.selectors

    user selects one of entries of layers, audios, actions, groups, timers, variables

    the tables of layers, audios, actions, groups, timers, variables are made with nanostore:set when user clicks one of the menu

    componentHandler is attached to the onClick event of menu and then each XXXStore:listener creates each table

    local function componentHandler(UI, storeTable)
      ...
      -- should we show the last secection?
      if storeTable == "layerTable" then
        UI.editor.layerStore:set(UI.scene.model.components.layers)
      elseif storeTable == "audioTable" then
        UI.editor.audioStore:set(UI.scene.model.components.audios)
      elseif storeTable == "groupTable" then
        UI.editor.groupStore:set(UI.scene.model.components.groups or {})
      elseif storeTable == "timerTable" then
        print(storeTable, #UI.scene.model.components.timers)
        UI.editor.timerStore:set(UI.scene.model.components.timers)
      elseif storeTable == "variableTable" then
        UI.editor.variableStore:set(UI.scene.model.components.variables)
      elseif storeTable == "actionTable" then
        UI.editor.actionStore:set(UI.scene.model.commands)
      end
      ...

    UI.scene.model.components.layers is rendered in editor.parts.layerTable

    local scene = require('controller.scene').new(sceneName, {
    name = "page1",
    components = {
      layers = {
            {  bg={
                              } },
            {  gotoBtn={ --class={"animation"}
                              } },
            {  title={ class={"linear"} } },
      },
      audios = {},
      groups = {},
      timers = {},
      variables = {},
      page = { }
    },
    commands = { "eventOne", "eventTwo", "act01" },
    onInit = function(scene) print("onInit") end
    })
    • editor.parts.layerTable

      the entries of componets.layers are recursively parsed

        local function parse(model)
          ...
          return name, class, children
        end
      
        local function render(models, xIndex, yIndex, parentObj)
          ...
          for i = 1, #models do
            local model = models[i]
            local entry = {}
            ...
            entry.name, entry.class, entry.children = parse(model)
            -- children
            if entry.children and  #entry.children > 0 then
            ...
              local childEntries, c = render(entry.children, xIndex + 1, count + yIndex, obj )
              for k, v in pairs(childEntries) do
                objs[#objs + 1] = v
              end
              obj.childEntries = childEntries
            end
          end
          ...
          return objs, count
        end
      
        UI.editor.layerStore:listen(
          function(foo, fooValue)
            M:destroy()
            M.selection = nil
            M.selections = {}
            M.objs = render(fooValue, 0, 0)
          end
        )

note: util.read() function parses “App/”..book.."/models/"..page .."/index.json"

...
ret.layers = parser(decoded)
...
setFiles(ret.audios, "/audios/short")
setFiles(ret.audios, "/audios/long")
setFiles(ret.groups, "/groups")
setFiles(ret.commands, "/commands")
return ret
{
  layers = {
    {name = "layerOne", parent="", children = {
        {name="childOne}, parent="layerOne", children = {}}
      }
    },
    {name = "layerTwo", parent="", children = {}},
  },
  audios = {}
}