-
September 17th, 2008, 06:25 #11
I lied: when I went back and looked at my code I found I had used a mixture of Tero's approach and my suggestion.
Context
The ruleset has a large array of spells, which fall into six classes (Contact, Enchantment, etc) and I want to show either a single class of spells, or all spells. The list which displays the spells then has a filter control (magnifying glass) to allow you to search for a sub-string in the spell name.
Approach
The database has a single list of spells. Each spell has a 'type' string node, and the library shortcuts include a 'source' node (which points to the single list) and a 'spelltype' node (which is either empty, to show the full list, or specifies which type of spell to display).
There is a custom reference window class which loads the spell data from its onInit handler by iterating over all of the nodes in the spell list and only adding those which match the spelltype criterion. The onFilter handler is then used to manage the filter control and only display entries which match the user's search string.
Example Data
The link entry in the reference module looks like this:
Code:<id-00002> <listlink type='windowreference'> <class>referencespells</class> <recordname>..</recordname> </listlink> <spelltype type='string'>Contact</spelltype> <source type='string'>reference.spells@Reference</source> </id-00002>
The spells themselves look like this:
Code:<reference> <spells> : <id-00069> <name type='string'>Contact Ghoul</name> <type type='string'>Contact</type> <text type='formattedtext'> <p>The spell costs 8 magic points to cast, and 1D3 Sanity points.Unless there are no ghouls nearby, it succeeds automatically. Ghouls are found wherever large concentrations of humans are, especially near graveyards and crypts. Places of burial more than a century old are propitious locations for this spell. Moonlit nights are best.</p> </text> </id-00069> : </spells> </reference>
The onInit event handler in the window class loads the spells from the source node that match the given spelltype:
Code:function onInit() local src = window.getDatabaseNode().createChild("source","string").getValue(); local source = nil; local spelltype = window.getDatabaseNode().createChild("spelltype","string").getValue(); if src and src~="" then source = DB.findNode(src); end if source then for k,node in pairs(source.getChildren()) do if spelltype=="" or node.createChild("type","string").getValue()==spelltype then createWindow(node); end end end end
That said, this stuff will be under OGL and therefore available for folks to examine and re-use once it hits the streets, provided you acknowledge DA's and SW's contribution.
Stuart
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks