Advertisement
kensuaga

FinalCodeScoundrelSheet

Aug 28th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 0 0
  1. --Character Sheet for Gloomhaven Scoundrel
  2. --Most the code was writen by Mr.Stump - To him I am greatful!
  3.  
  4.  
  5. --Saves the count value into a table (data_to_save) then encodes it into the Tabletop save
  6. function onSave()
  7. local data_to_save = {
  8. saved_countXP = countXP,
  9. saved_countGold = countGold,
  10. saved_ref_checkboxes = ref_checkboxes
  11. }
  12.  
  13. saved_data = JSON.encode(data_to_save)
  14. return saved_data
  15. end
  16.  
  17.  
  18. function onLoad(saved_data)
  19.  
  20. --Checks if there is a saved data. If there is, it gets the saved value for 'count'
  21. --saved_data = ''
  22. if saved_data != '' then
  23. local loaded_data = JSON.decode(saved_data)
  24. countXP = loaded_data.saved_countXP
  25. countGold = loaded_data.saved_countGold
  26. ref_checkboxes = loaded_data.saved_ref_checkboxes
  27. else
  28. --If there wasn't saved data, the default value is set to 0.
  29. countXP = 0
  30. countGold = 0
  31.  
  32. ref_checkboxes = {
  33.  
  34. --Notes Section
  35. {pos={0.211,0.1,0.386}, state=false},
  36. {pos={0.257,0.1,0.386}, state=false},
  37. {pos={0.302,0.1,0.386}, state=false},
  38.  
  39. {pos={0.409,0.1,0.386}, state=false},
  40. {pos={0.455,0.1,0.386}, state=false},
  41. {pos={0.500,0.1,0.386}, state=false},
  42.  
  43. {pos={0.606,0.1,0.386}, state=false},
  44. {pos={0.652,0.1,0.386}, state=false},
  45. {pos={0.697,0.1,0.386}, state=false},
  46.  
  47. {pos={0.211,0.1,0.445}, state=false},
  48. {pos={0.257,0.1,0.445}, state=false},
  49. {pos={0.302,0.1,0.445}, state=false},
  50.  
  51. {pos={0.409,0.1,0.445}, state=false},
  52. {pos={0.455,0.1,0.445}, state=false},
  53. {pos={0.500,0.1,0.445}, state=false},
  54.  
  55. {pos={0.606,0.1,0.445}, state=false},
  56. {pos={0.652,0.1,0.445}, state=false},
  57. {pos={0.697,0.1,0.445}, state=false},
  58.  
  59. --Perks Section
  60. {pos={0.163,0.1,-0.801}, state=false},
  61. {pos={0.212,0.1,-0.801}, state=false},
  62.  
  63. {pos={0.163,0.1,-0.726}, state=false},
  64.  
  65. {pos={0.163,0.1,-0.651}, state=false},
  66.  
  67. {pos={0.163,0.1,-0.527}, state=false},
  68.  
  69. {pos={0.163,0.1,-0.403}, state=false},
  70. {pos={0.212,0.1,-0.403}, state=false},
  71.  
  72. {pos={0.163,0.1,-0.276}, state=false},
  73. {pos={0.212,0.1,-0.276}, state=false},
  74.  
  75. {pos={0.163,0.1,-0.198}, state=false},
  76.  
  77. {pos={0.163,0.1,-0.123}, state=false},
  78. {pos={0.212,0.1,-0.123}, state=false},
  79.  
  80. {pos={0.163,0.1,-0.002}, state=false},
  81.  
  82. {pos={0.163,0.1,0.076}, state=false},
  83.  
  84. {pos={0.163,0.1,0.183}, state=false},
  85. }
  86. end
  87.  
  88.  
  89. --Tables for all the button paramiters
  90.  
  91. --Creates the checkboxes using the data from ref_checkboxes table
  92. -- button index 0-32 are used here
  93. createCheckboxes()
  94.  
  95. --Creates the paramaters used to build the XP, Gold and other labels buttons
  96. generateButtonParamiters()
  97.  
  98. --Updates the counter labels
  99. b_displayXP.label = tostring(countXP)
  100. b_displayGold.label = tostring(countGold)
  101.  
  102. -- Creates labels for XP, Gold and others
  103.  
  104.  
  105. self.createButton(b_displayXP) --index is 33
  106. self.createButton(b_plusXP)
  107. self.createButton(b_minusXP)
  108. self.createButton(b_plus5XP)
  109. self.createButton(b_minus5XP)
  110.  
  111. self.createButton(b_displayGold) --index is 38
  112. self.createButton(b_plusGold)
  113. self.createButton(b_minusGold)
  114. self.createButton(b_plus5Gold)
  115. self.createButton(b_minus5Gold)
  116.  
  117. self.createButton(label_update_parameters)
  118. self.createButton(label_name_parameters) --index is 44
  119. self.createButton(label_items_parameters) --index is 45
  120.  
  121. --Function to pull in character name and items
  122. updateSheet()
  123. end
  124.  
  125.  
  126. --Activates when + is hit. Adds 1 to 'count' then updates the display button.
  127. function increaseXP()
  128. countXP = countXP + 1
  129. updateDisplayXP()
  130. end
  131.  
  132. --Activates when - is hit. Subtracts 1 from 'count' then updates the display button.
  133. function decreaseXP()
  134. --Prevents count from going below 0
  135. if countXP > 0 then
  136. countXP = countXP - 1
  137. updateDisplayXP()
  138. end
  139. end
  140.  
  141. --Activates when + is hit. Adds 5 to 'count' then updates the display button.
  142. function increase5XP()
  143. countXP = countXP + 5
  144. updateDisplayXP()
  145. end
  146.  
  147. --Activates when - is hit. Subtracts 5 from 'count' then updates the display button.
  148. function decrease5XP()
  149. --Prevents count from going below 0
  150. if countXP > 4 then
  151. countXP = countXP - 5
  152. else
  153. countXP = 0
  154. end
  155. updateDisplayXP()
  156. end
  157.  
  158.  
  159. --function that updates the XP Counter display. Triggered whenever 'countxp' is changed
  160. function updateDisplayXP()
  161.  
  162. --b_displayXP.label = tostring(countXP)
  163. --self.editButton(b_displayXP)
  164. self.editButton({index = 33, label = tostring(countXP)})
  165.  
  166. end
  167.  
  168.  
  169.  
  170. --Activates when + is hit. Adds 1 to 'count' then updates the display button.
  171. function increaseGold()
  172. countGold = countGold + 1
  173. updateDisplayGold()
  174. end
  175.  
  176. --Activates when - is hit. Subtracts 1 from 'count' then updates the display button.
  177. function decreaseGold()
  178. --Prevents count from going below 0
  179. if countGold > 0 then
  180. countGold = countGold - 1
  181. updateDisplayGold()
  182. end
  183. end
  184.  
  185. --Activates when + is hit. Adds 5 to 'count' then updates the display button.
  186. function increase5Gold()
  187. countGold = countGold + 5
  188. updateDisplayGold()
  189. end
  190.  
  191. --Activates when - is hit. Subtracts 5 from 'count' then updates the display button.
  192. function decrease5Gold()
  193. --Prevents count from going below 0
  194. if countGold > 4 then
  195. countGold = countGold - 5
  196. else
  197. countGold = 0
  198. end
  199. updateDisplayGold()
  200. end
  201.  
  202.  
  203. --function that updates the Gold Counter display.
  204. function updateDisplayGold()
  205.  
  206. --b_displayGold.label = tostring(countGold)
  207. --self.editButton(b_displayGold)
  208. self.editButton({index = 38, label = tostring(countGold)})
  209. end
  210.  
  211.  
  212.  
  213. function updateSheet()
  214. local name = self.getName()
  215. self.editButton({index = 44, label = tostring(name)})
  216.  
  217. local items = self.getDescription()
  218. self.editButton({index = 45, label = tostring(items)})
  219. end
  220.  
  221.  
  222. function createCheckboxes()
  223. --print('createCheckboxes funcatoin has been called')
  224. for i, boxData in ipairs(ref_checkboxes) do
  225. --Set up the function trigger
  226. local funcName = "checkbox"..i
  227. local func = function() toggleCheck(i) end
  228. self.setVar(funcName, func)
  229. --Set the X
  230. local label = ""
  231. print(tostring(label))
  232. if boxData.state == true then label = "X" end
  233. --Make the button
  234. self.createButton({
  235. click_function = funcName, function_owner = self, label = label,
  236. position =boxData.pos, width = 150, height = 150, font_size = 145,
  237. scale = {0.1,0.1,0.1}
  238. })
  239. end
  240. end
  241.  
  242. function toggleCheck(i)
  243. if ref_checkboxes[i].state == true then
  244. self.editButton({index=i-1, label=""})
  245. ref_checkboxes[i].state = false
  246. else
  247. self.editButton({index=i-1, label="X"})
  248. ref_checkboxes[i].state = true
  249. end
  250. end
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. function generateButtonParamiters()
  262.  
  263. -- Sets all the paramiters for the XP counter
  264. -- Sets XYZ center position for all buttons
  265.  
  266. xpXPos = -0.3
  267. xpYPos = 0.1
  268. xpZPos = -0.35
  269. lableScale = 0.20
  270.  
  271. b_displayXP = {
  272. index = 0, click_function="none", function_owner = self, label = '',
  273. position = {xpXPos,xpYPos,xpZPos}, width = 0, height = 0,
  274. font_size = 500, scale = {lableScale,lableScale,lableScale}
  275. }
  276.  
  277. b_plusXP = {
  278. click_function = 'increaseXP', function_owner = self, label = '+1',
  279. position = {xpXPos + 0.15,xpYPos, xpZPos + 0.05}, width = 150,
  280. height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
  281. }
  282.  
  283. b_minusXP = {
  284. click_function = 'decreaseXP', function_owner = self, label = '-1',
  285. position = {xpXPos + -0.15,xpYPos, xpZPos + 0.05}, width = 150,
  286. height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
  287. }
  288.  
  289. b_plus5XP = {
  290. click_function = 'increase5XP', function_owner = self, label = '+5',
  291. position = {xpXPos + 0.15,xpYPos, xpZPos + -0.07}, width = 150,
  292. height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
  293. }
  294.  
  295. b_minus5XP = {
  296. click_function = 'decrease5XP', function_owner = self, label = '-5',
  297. position = {xpXPos + -0.15,xpYPos, xpZPos + -0.07}, width = 150,
  298. height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
  299. }
  300.  
  301.  
  302. -- Sets all the paramiters for the Gold counter
  303. -- Sets XYZ center position for all buttons
  304.  
  305. goldXPos = -0.3
  306. goldYPos = 0.1
  307. goldZPos = -0.05
  308.  
  309.  
  310. b_displayGold = {
  311. click_function="none", function_owner = self, label = '',
  312. position = {goldXPos,goldYPos,goldZPos}, width = 0, height = 0,
  313. font_size = 500, scale = {lableScale,lableScale,lableScale}
  314. }
  315.  
  316. b_plusGold = {
  317. click_function = 'increaseGold', function_owner = self, label = '+1',
  318. position = {goldXPos + 0.15,goldYPos, goldZPos + 0.05}, width = 150,
  319. height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
  320. }
  321.  
  322. b_minusGold = {
  323. click_function = 'decreaseGold', function_owner = self, label = '-1',
  324. position = {goldXPos + -0.15,goldYPos, goldZPos + 0.05}, width = 150,
  325. height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
  326. }
  327.  
  328. b_plus5Gold = {
  329. click_function = 'increase5Gold', function_owner = self, label = '+5',
  330. position = {goldXPos + 0.15,goldYPos, goldZPos + -0.07}, width = 150,
  331. height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
  332. }
  333.  
  334. b_minus5Gold = {
  335. click_function = 'decrease5Gold', function_owner = self, label = '-5',
  336. position = {goldXPos + -0.15,goldYPos, goldZPos + -0.07}, width = 150,
  337. height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
  338. }
  339.  
  340.  
  341. --Label to update character name and iteam list
  342. label_update_parameters = {
  343. click_function="updateSheet", function_owner=self, label='Update',
  344. position={-0.74,0.15,-0.96}, rotation={0,0,0}, height=60, width=420,
  345. font_size=100, scale = {0.15,0.15,0.15}
  346. }
  347.  
  348.  
  349. -- Label for character name
  350. label_name_parameters = {
  351. click_function="none", function_owner=self, label='',
  352. position={-0.3,0.15,-0.72}, rotation={0,0,0}, height=0, width=0,
  353. font_size=100, scale = {0.3,0.3,0.3}
  354. }
  355.  
  356. --When alingment left works use position={-0.7,0.15,0.2}
  357. label_items_parameters = {
  358. click_function="none", function_owner=self, label='',
  359. position={-0.3,0.15,0.4}, rotation={0,0,0}, height=0, width=0,
  360. font_size=100, scale = {0.3,0.3,0.3},
  361. }
  362.  
  363. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement