Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Expand tokens from a field to populate another field, using a lookup table.
- -- May 12, 2020.
- -- Written by Theo Serror
- -- Based on the "Separate Last Items" workflow
- local function setup(prefs)
- local categoryTable = {
- ['A']='ANIMAUX',
- ['B']='BRUITAGES',
- ['C']='CHOCS, CLOCHES',
- ['D']='DOMESTIQUE',
- ['E']='ÉLECTRICITÉ',
- ['F']='FONDS',
- ['G']='ARMES, EXPLOSIONS, DÉBRIS',
- ['H']='HUMAINS',
- ['I']='INDUSTRIE, CHANTIER',
- ['M']='MÉCANISMES',
- ['N']='NATURE',
- ['P']='ALARMES, SIRÈNES',
- ['S']='SUBS, RUMBLES',
- ['T']='TRANSPORTS',
- ['TXT']='TEXTE',
- ['V']='VILLE',
- ['X']='SFX',
- ['Z']='MUSIQUE'}
- return function (metadata)
- local changedMetadata={}
- local stringSplitter=smstringarray(metadata[prefs.field] or '',prefs.splitchar)
- stringSplitter:trim() -- trim any whitespace
- local count=tonumber(prefs.count)
- local v=stringSplitter:getTable()
- local token=v[1]
- if categoryTable[token] then
- changedMetadata[prefs.destfield]=categoryTable[token]
- else
- changedMetadata[prefs.destfield]=''
- end
- return changedMetadata
- end
- end
- function buildUI()
- local builder=smbuilder()
- local v=builder:createView('{"text":"PARSE FIELD TOKEN","bounds" : "0,0,parent.width,120"}')
- assert(v,"unable to create view object")
- local c=nil
- c=builder:create('label','{"bounds":"20,42,190,67","text":"Parse token from", "align" : "left"}')
- assert(c) -- will be a table with a userdata
- assert(builder:create('combo','{"id" : "field", "options" : "stringFields", "bounds":"200,42,340,67","text":"Description"}'))
- assert(builder:create('label','{"id" : "from", "bounds":"345,42,520,67","text":"before character" ,"align" : "centre"}'))
- assert(builder:create('edit','{"id" : "splitchar", "bounds":"525,42,545,67","text":"_"}'))
- assert(builder:create('label','{"id" : "from", "bounds":"20,72,190,97","text":"Expand it into","align" : "left"}'))
- assert(builder:create('combo','{"id" : "destfield", "options" : "stringFields", "bounds":"200,72,295,97","text":"FXName"}'))
- builder:register(v,setup)
- -- Now inject this
- return v
- end
- --[[ ========================================================== ]]--
- return buildUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement