MissEshock2002

SexScripts Load List Example

Aug 6th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 5.61 KB | None | 0 0
  1. // Load List Example
  2. // by MissEshock2002
  3.  
  4. // This script, from https://ss.deviatenow.com, is protected by this licence:
  5. // CC0
  6.  
  7. setInfos(9, "Load List Example",
  8.         "Load List from 'data.properties'",
  9.         "MissEshock2002",
  10.         "v1.0", 0x222222, "en", ["example", "tutorial"]);
  11.  
  12. String SCRIPTNAME = "LoadListExample"
  13. List exampleIntList = [1, 2, 3]
  14. List exampleFloatList = [1.2, 3.4, 5.6]
  15. List exampleStringList = ["A", "B", "C"]
  16. List exampleBoolList = [true, true, false]
  17. save(SCRIPTNAME + ".exampleIntList", exampleIntList)
  18. save(SCRIPTNAME + ".exampleFloatList", exampleFloatList)
  19. save(SCRIPTNAME + ".exampleStringList", exampleStringList)
  20. save(SCRIPTNAME + ".exampleBoolList", exampleBoolList)
  21. String savedListsText = "Saved lists: " +
  22.         "\nexampleIntList = " + exampleIntList +
  23.         "\nexampleFloatList = " + exampleFloatList +
  24.         "\nexampleStringList = " + exampleStringList +
  25.         "\nexampleBoolList = " + exampleBoolList
  26.  
  27. def loadIntegerList = { String scriptName, String listName ->
  28.     // return list with Integers from 'data.properties'
  29.     List tempList = []
  30.     int listIndex = 0
  31.     while (true) {
  32.         def listItem = loadInteger(SCRIPTNAME + "." + listName + "." + listIndex)
  33.         if (listItem != null) tempList.add(listItem)
  34.         else break
  35.         listIndex++
  36.     }
  37.     return tempList
  38. }
  39.  
  40. def loadFloatList = { String scriptName, String listName ->
  41.     // return list with Floats from 'data.properties'
  42.     List tempList = []
  43.     int listIndex = 0
  44.     while (true) {
  45.         def listItem = loadFloat(SCRIPTNAME + "." + listName + "." + listIndex)
  46.         if (listItem != null) tempList.add(listItem)
  47.         else break
  48.         listIndex++
  49.     }
  50.     return tempList
  51. }
  52.  
  53. def loadStringList = { String scriptName, String listName ->
  54.     // return list with Strings from 'data.properties'
  55.     List tempList = []
  56.     int listIndex = 0
  57.     while (true) {
  58.         def listItem = loadString(SCRIPTNAME + "." + listName + "." + listIndex)
  59.         if (listItem != null) tempList.add(listItem)
  60.         else break
  61.         listIndex++
  62.     }
  63.     return tempList
  64. }
  65.  
  66. def loadBooleanList = { String scriptName, String listName ->
  67.     // return list with Booleans from 'data.properties'
  68.     List tempList = []
  69.     int listIndex = 0
  70.     while (true) {
  71.         def listItem = loadBoolean(SCRIPTNAME + "." + listName + "." + listIndex)
  72.         if (listItem != null) tempList.add(listItem)
  73.         else break
  74.         listIndex++
  75.     }
  76.     return tempList
  77. }
  78.  
  79. def loadList = { String scriptName, String listName ->
  80.     // return list with listName from 'data.properties'
  81.     // detects data type
  82.     List listOfStrings = []
  83.     int listIndex = 0
  84.     while (true) {
  85.         def listItem = loadString(SCRIPTNAME + "." + listName + "." + listIndex)
  86.         if (listItem != null) listOfStrings.add(listItem)
  87.         else break
  88.         listIndex++
  89.     }
  90.  
  91.     List tempList = []
  92.     if (listOfStrings.every { it -> it.isNumber() }) {
  93.         if (listOfStrings.every { it -> it.isInteger() }) {
  94.             listOfStrings.each { it -> tempList.add(it.toInteger()) }
  95.             return tempList
  96.         } else if (listOfStrings.any { it -> it.isFloat() }) {
  97.             listOfStrings.each { it -> tempList.add(it.toFloat()) }
  98.             return tempList
  99.         }
  100.     } else if (listOfStrings.every { it -> (it in ["true", "false"]) }) {
  101.         listOfStrings.each { it ->
  102.             if (it == "true") tempList.add(true)
  103.             else tempList.add(false)
  104.         }
  105.         return tempList
  106.     } else {
  107.         return listOfStrings
  108.     }
  109. }
  110.  
  111. def getListOverview = { list ->
  112.     return savedListsText +
  113.             "\n\nLoaded list: " +
  114.             "\nlist = " + list.toString() +
  115.             "\nlist.size() = " + list.size() +
  116.             "\nlist.isEmpty() = " + list.isEmpty() +
  117.             "\nlist[0].getClass() = " + list[0].getClass()
  118. }
  119.  
  120. List menuList = ["Load Integer List", "Load Float List", "Load String List", "Load Boolean List"]
  121.  
  122. List loadedList = []
  123.  
  124. boolean endLoop = false
  125. while (!endLoop) { // loop repeats till endLoop = true
  126.  
  127.     show("In this example lists are load by known data type.\n" +
  128.             "The items in the saved list must have the same data type: Integer, Float, String or Boolean.\n\n" +
  129.             getListOverview(loadedList))
  130.  
  131.     int sel = getSelectedValue(null, menuList + "Next")
  132.     if (sel == 0) {
  133.         loadedList = loadIntegerList(SCRIPTNAME, "exampleIntList")
  134.     } else if (sel == 1) {
  135.         loadedList = loadFloatList(SCRIPTNAME, "exampleFloatList")
  136.     } else if (sel == 2) {
  137.         loadedList = loadStringList(SCRIPTNAME, "exampleStringList")
  138.     } else if (sel == 3) {
  139.         loadedList = loadBooleanList(SCRIPTNAME, "exampleBoolList")
  140.     } else {
  141.         endLoop = true
  142.     }
  143. }
  144.  
  145. endLoop = false
  146. while (!endLoop) { // loop repeats till endLoop = true
  147.  
  148.     show("In this example lists are load by unknown data type. The data type is guessed by the items in the list.\n" +
  149.             "The items in the saved list must have the same data type: Integer, Float, String or Boolean.\n\n" +
  150.             getListOverview(loadedList))
  151.  
  152.     int sel = getSelectedValue(null, menuList + "End")
  153.     if (sel == 0) {
  154.         loadedList = loadList(SCRIPTNAME, "exampleIntList")
  155.     } else if (sel == 1) {
  156.         loadedList = loadList(SCRIPTNAME, "exampleFloatList")
  157.     } else if (sel == 2) {
  158.         loadedList = loadList(SCRIPTNAME, "exampleStringList")
  159.     } else if (sel == 3) {
  160.         loadedList = loadList(SCRIPTNAME, "exampleBoolList")
  161.     } else {
  162.         endLoop = true
  163.     }
  164. }
  165.  
  166. show("- End of Script -")
Add Comment
Please, Sign In to add comment