Advertisement
Guest User

Parse Field Token

a guest
Jul 2nd, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. -- Expand tokens from a field to populate another field, using a lookup table.
  2. -- May 12, 2020.
  3. -- Written by Theo Serror
  4. -- Based on the "Separate Last Items" workflow
  5.  
  6. local function setup(prefs)
  7. local categoryTable = {
  8. ['A']='ANIMAUX',
  9. ['B']='BRUITAGES',
  10. ['C']='CHOCS, CLOCHES',
  11. ['D']='DOMESTIQUE',
  12. ['E']='ÉLECTRICITÉ',
  13. ['F']='FONDS',
  14. ['G']='ARMES, EXPLOSIONS, DÉBRIS',
  15. ['H']='HUMAINS',
  16. ['I']='INDUSTRIE, CHANTIER',
  17. ['M']='MÉCANISMES',
  18. ['N']='NATURE',
  19. ['P']='ALARMES, SIRÈNES',
  20. ['S']='SUBS, RUMBLES',
  21. ['T']='TRANSPORTS',
  22. ['TXT']='TEXTE',
  23. ['V']='VILLE',
  24. ['X']='SFX',
  25. ['Z']='MUSIQUE'}
  26.  
  27. return function (metadata)
  28.  
  29. local changedMetadata={}
  30. local stringSplitter=smstringarray(metadata[prefs.field] or '',prefs.splitchar)
  31. stringSplitter:trim() -- trim any whitespace
  32.  
  33. local count=tonumber(prefs.count)
  34. local v=stringSplitter:getTable()
  35. local token=v[1]
  36. if categoryTable[token] then
  37. changedMetadata[prefs.destfield]=categoryTable[token]
  38. else
  39. changedMetadata[prefs.destfield]=''
  40. end
  41.  
  42. return changedMetadata
  43. end
  44. end
  45.  
  46. function buildUI()
  47.  
  48. local builder=smbuilder()
  49. local v=builder:createView('{"text":"PARSE FIELD TOKEN","bounds" : "0,0,parent.width,120"}')
  50. assert(v,"unable to create view object")
  51. local c=nil
  52.  
  53. c=builder:create('label','{"bounds":"20,42,190,67","text":"Parse token from", "align" : "left"}')
  54. assert(c) -- will be a table with a userdata
  55. assert(builder:create('combo','{"id" : "field", "options" : "stringFields", "bounds":"200,42,340,67","text":"Description"}'))
  56. assert(builder:create('label','{"id" : "from", "bounds":"345,42,520,67","text":"before character" ,"align" : "centre"}'))
  57. assert(builder:create('edit','{"id" : "splitchar", "bounds":"525,42,545,67","text":"_"}'))
  58. assert(builder:create('label','{"id" : "from", "bounds":"20,72,190,97","text":"Expand it into","align" : "left"}'))
  59. assert(builder:create('combo','{"id" : "destfield", "options" : "stringFields", "bounds":"200,72,295,97","text":"FXName"}'))
  60. builder:register(v,setup)
  61. -- Now inject this
  62. return v
  63.  
  64. end
  65. --[[ ========================================================== ]]--
  66. return buildUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement