1- local SavedGames = require (" apps.adventure-arena.models.SavedGames" )
21local Session = require (" apps.adventure-arena.zilscript.zilscript.reader.Session" )
32local JsonDocument = require (" apps.adventure-arena.services.JsonDocument" )
43local Store = require (" apps.adventure-arena.Store" )
@@ -17,10 +16,6 @@ local DOCUMENTS = {
1716 onboarding = " adventure-arena/onboarding.json" ,
1817}
1918
20- -- Tabs in template order; each owns a navigation stack so a page opens in
21- -- the tab the tap came from.
22- local TABS = { " library" , " bookshelf" , " create" , " settings" , " search" }
23-
2419local Controller = {}
2520Controller .__index = Controller
2621
@@ -61,15 +56,8 @@ function Controller.new(options)
6156 self .pages = PageHost .new (ns , {
6257 push = function (id , state ) return self :pushPage (id , state ) end ,
6358 back = function () return self :back () end ,
64- focus = function (origin ) self :focus (origin ) end ,
65- selectTab = function (name ) return self :selectTab (name ) end ,
66- tabChanged = function (index )
67- self .selectedTab = index
68- self :focus (TABS [index + 1 ])
69- end ,
59+ openCatalogPage = function (id ) return self :openCatalogPage (id ) end ,
7060 openSession = function (id , fresh ) return self .sessionController :show (id , fresh ) end ,
71- resume = function () return self :resumeLatest () end ,
72- showAccessory = function (resumable ) self :showAccessory (resumable ) end ,
7361 openGuide = function () self .onboarding :openGuide (self .window ) end ,
7462 mountReadingOptions = function (host ) self :mountReadingOptions (host ) end ,
7563 })
@@ -141,90 +129,55 @@ function Controller:back()
141129 self .navigation :pop ()
142130end
143131
144- function Controller :focus (origin )
145- local navigation = self .navigations and self .navigations [origin ]
146- if navigation then self .navigation = navigation end
147- end
132+ function Controller :openCatalogPage (id )
133+ if id == " create" then return self :push (" pages/Create" , {}) end
148134
149- -- Discover / Library / Create / Settings / Search, matching Tabs.etlua.
150- function Controller :selectTab (name )
151- local index
152- for i , key in ipairs (TABS ) do
153- if key == name then index = i - 1 break end
135+ local template , data
136+ if id == " search" then
137+ template , data = " pages/Search" , self .pages :data (" search" )
138+ else
139+ assert (id == " settings" , " unknown catalog page" )
140+ template , data = " layouts/CatalogPage" , { title = " Settings" , actions = {} }
154141 end
155- if not index then return false end
156- self .selectedTab = index
157- self :focus (name )
158- if self .tabs then self .tabs :selectTab (index ) end
159- return true
160- end
161-
162- -- The accessory resumes the latest story in whichever tab is showing.
163- function Controller :resumeLatest ()
164- local latest = SavedGames :latest ()
165- if not latest then return false end
166- self :focus (TABS [(self .selectedTab or 0 ) + 1 ])
167- return self .sessionController :show (latest .gameId )
142+ data .actions .closeCatalogPage = function ()
143+ if id == " settings" then
144+ self .readingOptions :unmount (self .catalogReadingOptions )
145+ self .catalogReadingOptions , self .readingHost = nil , nil
146+ end
147+ self .pages :unmount (id )
148+ end
149+ local _ , refs = self :push (template , data )
150+ self .pages :mount (id , refs .catalogContent )
168151end
169152
170- -- Discover's data and the actions of every page the window layout names:
171- -- Discover's own, and the search field's.
172153function Controller :libraryData ()
173154 local library = self .pages :data (" discover" )
174- local actions = {}
175- for name , action in pairs (library .actions ) do actions [name ] = action end
176- actions .search = self .pages :data (" search" ).actions .search
177- return { library = library , actions = actions }
155+ return { library = library , actions = library .actions }
178156end
179157
180- -- Everything that shows reading progress: the Discover shelf, the Library
181- -- tab and the tab bar accessory, each asked again.
182158function Controller :refreshProgress ()
183159 self .pages :refresh ()
184160end
185161
186- -- An open book hides the accessory with the tab bar, as does having
187- -- nothing to resume.
188- function Controller :showAccessory (resumable )
189- if self .tabs then self .tabs .accessoryHidden = not resumable or self .sessionController :isOpen () end
190- end
191-
192162-- The reading options are shared with the in-book sheet: mounted once per
193163-- host the Settings page draws.
194164function Controller :mountReadingOptions (host )
195165 if not host or self .readingHost == host then return end
166+ self .readingOptions :unmount (self .catalogReadingOptions )
196167 self .readingHost = host
197- self .readingOptions :mount (host , true )
198- end
199-
200- function Controller :attach (refs )
201- local pages = self .pages
202- -- An empty catalog shows its empty state and has no shelf to fill.
203- if refs .continueShelf then pages :mount (" continueShelf" , refs .continueShelf ) end
204- if refs .bookshelf then pages :mount (" bookshelf" , refs .bookshelf ) end
205- if refs .nowReading then pages :mount (" nowReading" , refs .nowReading ) end
206- if refs .searchResults then pages :mount (" search" , refs .searchResults ) end
207- if refs .settings then pages :mount (" settings" , refs .settings ) end
168+ self .catalogReadingOptions = self .readingOptions :mount (host , true )
208169end
209170
210171function Controller :home ()
211172 local _ , refs = xml .renderFile (VIEWS .. " layouts/Home.etlua" , self :libraryData (), self .ns )
212173 self .navigation = refs .navigation
213- self .navigations = { library = refs .navigation }
214- self :attach (refs )
215174 return self .navigation
216175end
217176
218177function Controller :createWindow ()
219178 local config , refs = xml .renderFile (VIEWS .. " layouts/Window.etlua" , self :libraryData (), self .ns )
220179 self .navigation = refs .navigation
221- self .navigations = {
222- library = refs .navigation , bookshelf = refs .bookshelfNavigation , create = refs .createNavigation ,
223- settings = refs .settingsNavigation , search = refs .searchNavigation ,
224- }
225- self .tabs = refs .tabs
226180 self .window = self .ns .Window (config )
227- self :attach (refs )
228181 -- Headless runs drive the tour themselves; a live launch shows it once.
229182 if not rawget (_G , " __headless" ) and self .onboarding :needed () then
230183 self .onboarding :open (self .window )
0 commit comments