Advertisement
thepowderguy

Script creator

May 22nd, 2013
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.14 KB | None | 0 0
  1. SC_UI = Window:new(40, 50, 542, 302)
  2.  
  3. title = Label:new(274, 4, 1, 16, "\bb================================ \brLua element creator\bb ================================")
  4. ins = Label:new(274, 24, 1, 16, "\boEnter values into boxes. If you don't know what they are, look at the wiki. Leave blank to not write that line.\n Temperature values are floats batween 0 - 10000, transition values and 'Base' have to be an element name.")
  5.  
  6. scriptname = Textbox:new(6, 50, 128, 16, "" , "Name of script")
  7. Ident = Textbox:new(6, 70, 128, 16, "" , "Element id prefix")
  8. elName = Textbox:new(6, 90, 128, 16, "" , "Name (all in capitals)")
  9. Base = Textbox:new(6, 110, 128, 16, "" , "Base element")
  10. Color = Textbox:new(6, 130, 128, 16, "" , "Color (6 digit hex)")
  11. MenuVisible = Textbox:new(6, 150, 128, 16, "" , "MenuVisible (1 or 0)")
  12. MenuSection = Textbox:new(6, 170, 128, 16, "" , "MenuSection")
  13. Advection = Textbox:new(6, 190, 128, 16, "" , "Advection (-1 to 1 float)")
  14.  
  15. AirDrag = Textbox:new(140, 50, 128, 16, "" , "AirDrag (any float)")
  16. AirLoss = Textbox:new(140, 70, 128, 16, "" , "AirLoss (0 to 1 float)")
  17. Loss = Textbox:new(140, 90, 128, 16, "" , "Loss (any float)")
  18. Collision = Textbox:new(140, 110, 128, 16, "" , "Collision (any float)")
  19. Gravity = Textbox:new(140, 130, 128, 16, "" , "Gravity (any float)")
  20. Diffusion = Textbox:new(140, 150, 128, 16, "" , "Diffusion (any float)")
  21. HotAir = Textbox:new(140, 170, 128, 16, "" , "HotAir (very small float)")
  22. Falldown = Textbox:new(140, 190, 128, 16, "" , "Falldown (0, 1, or 2)")
  23.  
  24. Flammable = Textbox:new(274, 50, 128, 16, "" , "Flammable (0+ integer)")
  25. Explosive = Textbox:new(274, 70, 128, 16, "" , "Explosive (0, 1, or 2)")
  26. Meltable = Textbox:new(274, 90, 128, 16, "" , "Meltable (1 or 0)")
  27. Hardness = Textbox:new(274, 110, 128, 16, "" , "Hardness (0+ integer)")
  28. Weight = Textbox:new(274, 130, 128, 16, "" , "Weight (-1 to 100)")
  29. Temperature = Textbox:new(274, 150, 128, 16, "" , "Temperature (temp value)")
  30. HeatConduct = Textbox:new(274, 170, 128, 16, "" , "HeatConduct (0 to 255)")
  31. Description = Textbox:new(6, 210, 530, 16, "" , "Description (text that describes the element)")  
  32.  
  33. HighTemperature = Textbox:new(408, 50, 128, 16, "" , "HighTemperature (temp)")
  34. HighTemperatureTransition = Textbox:new(408, 70, 128, 16, "" , "HighTemperatureTranstion")
  35. LowTemperature = Textbox:new(408, 90, 128, 16, "" , "LowTemperature (temp)")
  36. LowTemperatureTransition = Textbox:new(408, 110, 128, 16, "" , "LowTemperatureTransition")
  37. HighPressure = Textbox:new(408, 130, 128, 16, "" , "HighPressure (0 to 256)")
  38. HighPressureTransition = Textbox:new(408, 150, 128, 16, "" , "HighPressureTranstion")
  39. LowPressure = Textbox:new(408, 170, 128, 16, "" , "LowPressure (-256 to 0)")
  40. LowPressureTransition = Textbox:new(408, 190, 128, 16, "" , "LowPressureTranstion")
  41.  
  42. State = Textbox:new(274, 190, 128, 16, "" , "State (constant)")
  43. Properties = Textbox:new(6, 230, 530, 16, "" , "Properties (one constant or multiple constants using bit.bor)")
  44.  
  45. Create = Button:new(6, 276, 262, 20, "\btCreate script", "")
  46. Create:action(function(sender) create_script() end)
  47. Close = Button:new(0, 0, 14, 14, "\brx", "")
  48. Close:action(function(sender) interface.closeWindow(SC_UI) end)
  49. Reset = Button:new(274, 276, 262, 20, "\btReset all values", "")
  50. Reset:action(function(sender) reset() end)
  51.  
  52. Update = Checkbox:new(6, 256, 16, 16, "\brMake update function frame (main element function)")
  53. Update:checked(true)
  54. Graphics = Checkbox:new(274, 256, 16, 16, "\brMake graphics function frame (deals with graphics)")
  55. Graphics:checked(true)
  56.  
  57. function open(key)
  58.     if key == 'j' then
  59.         interface.showWindow(SC_UI)
  60.     end
  61. end
  62.  
  63. function reset()
  64.     scriptname:text("")
  65.     Ident:text("")
  66.     elName:text("")
  67.     Base:text("")
  68.     Color:text("")
  69.     MenuVisible:text("")
  70.     MenuSection:text("")
  71.     Advection:text("")
  72.    
  73.     AirDrag:text("")
  74.     AirLoss:text("")
  75.     Loss:text("")
  76.     Collision:text("")
  77.     Gravity:text("")
  78.     Diffusion:text("")
  79.     HotAir:text("")
  80.     Falldown:text("")
  81.    
  82.     Flammable:text("")
  83.     Explosive:text("")
  84.     Meltable:text("")
  85.     Hardness:text("")
  86.     Weight:text("")
  87.     Temperature:text("")
  88.     HeatConduct:text("")
  89.     Description:text("")
  90.    
  91.     HighTemperature:text("")
  92.     HighTemperatureTransition:text("")
  93.     LowTemperature:text("")
  94.     LowTemperatureTransition:text("")
  95.     HighPressure:text("")
  96.     HighPressureTransition:text("")
  97.     LowPressure:text("")
  98.     LowPressureTransition:text("")
  99.  
  100.     State:text("")
  101.     Properties:text("")
  102. end
  103.  
  104. function create_script()
  105.     if scriptname:text() == "" then
  106.         tpt.throw_error("Specified file must have name, so give it a name!")
  107.     elseif Ident:text() == "" or elName:text() == "" or Base:text() == "" or Color:text() == "" or Description:text() == "" then
  108.         tpt.throw_error("Prefix, Name, Base element, Color, Description all have to have values!")
  109.     else
  110.         FullName = "elements.property(elements." .. Ident:text() .. "_PT_" .. elName:text()
  111.         script = io.open(scriptname:text() .. ".lua", "w")
  112.         script:write("--created with thepowderguy's script\n\n")
  113.         script:write("local NewElement = elements.allocate(\"" .. Ident:text() .. "\", \"" .. elName:text() .. "\")\n")
  114.         script:write("elements.element(elements." .. Ident:text() .. "_PT_" .. elName:text() .. ", elements.element(tpt.element(\"" .. Base:text() .. "\")))\n")
  115.         script:write(FullName .. ", \"Name\", \"" .. elName:text() .. "\")\n")
  116.         script:write(FullName .. ", \"Color\", " .. Color:text() .. ")\n")
  117.  
  118. -- START OF PROPERTIES
  119.  
  120.         if MenuVisible:text() ~= "" then
  121.             script:write(FullName .. ", \"MenuVisible\", " .. MenuVisible:text() .. ")\n")
  122.         end
  123.         if MenuSection:text() ~= "" then
  124.             script:write(FullName .. ", \"MenuSection\", " .. MenuSection:text() .. ")\n")
  125.         end
  126.         if Advection:text() ~= "" then
  127.             script:write(FullName .. ", \"Advection\", " .. Advection:text() .. ")\n")
  128.         end
  129.         if AirDrag:text() ~= "" then
  130.             script:write(FullName .. ", \"AirDrag\", " .. AirDrag:text() .. ")\n")
  131.         end
  132.         if AirLoss:text() ~= "" then
  133.             script:write(FullName .. ", \"AirLoss\", " .. AirLoss:text() .. ")\n")
  134.         end
  135.         if Loss:text() ~= "" then
  136.             script:write(FullName .. ", \"Loss\", " .. Loss:text() .. ")\n")
  137.         end
  138.         if Collision:text() ~= "" then
  139.             script:write(FullName .. ", \"Collision\", " .. Collision:text() .. ")\n")
  140.         end
  141.         if Gravity:text() ~= "" then
  142.             script:write(FullName .. ", \"Gravity\", " .. Gravity:text() .. ")\n")
  143.         end
  144.         if Diffusion:text() ~= "" then
  145.             script:write(FullName .. ", \"Diffusion\", " .. Diffusion:text() .. ")\n")
  146.         end
  147.         if HotAir:text() ~= "" then
  148.             script:write(FullName .. ", \"HotAir\", " .. HotAir:text() .. ")\n")
  149.         end
  150.         if Falldown:text() ~= "" then
  151.             script:write(FullName .. ", \"Falldown\", " .. Falldown:text() .. ")\n")
  152.         end
  153.         if Flammable:text() ~= "" then
  154.             script:write(FullName .. ", \"Flammable\", " .. Flammable:text() .. ")\n")
  155.         end
  156.         if Explosive:text() ~= "" then
  157.             script:write(FullName .. ", \"Explosive\", " .. Explosive:text() .. ")\n")
  158.         end
  159.         if Meltable:text() ~= "" then
  160.             script:write(FullName .. ", \"Meltable\", " .. Meltable:text() .. ")\n")
  161.         end
  162.         if Hardness:text() ~= "" then
  163.             script:write(FullName .. ", \"Hardness\", " .. Hardness:text() .. ")\n")
  164.         end
  165.         if Weight:text() ~= "" then
  166.             script:write(FullName .. ", \"Weight\", " .. Weight:text() .. ")\n")
  167.         end
  168.         if Temperature:text() ~= "" then
  169.             script:write(FullName .. ", \"Temperature\", " .. Temperature:text() .. ")\n")
  170.         end
  171.         if HeatConduct:text() ~= "" then
  172.             script:write(FullName .. ", \"HeatConduct\", " .. HeatConduct:text() .. ")\n")
  173.         end
  174.         if Description:text() ~= "" then
  175.             script:write(FullName .. ", \"Description\", \"" .. Description:text() .. "\")\n")
  176.         end
  177.         if State:text() ~= "" then
  178.             script:write(FullName .. ", \"State\", " .. State:text() .. ")\n")
  179.         end
  180.         if Properties:text() ~= "" then
  181.             script:write(FullName .. ", \"Properties\", " .. Properties:text() .. ")\n")
  182.         end
  183.  
  184. -- START OF TRANSITIONS
  185.  
  186.         if HighTemperature:text() ~= "" then
  187.             script:write(FullName .. ", \"HighTemperature\", " .. HighTemperature:text() .. ")\n")
  188.         end
  189.         if HighTemperatureTransition:text() ~= "" then
  190.             script:write(FullName .. ", \"HighTemperatureTransition\", " .. "tpt.element(\"" .. HighTemperatureTransition:text() .. "\"))\n")
  191.         end
  192.         if LowTemperature:text() ~= "" then
  193.             script:write(FullName .. ", \"LowTemperature\", " .. LowTemperature:text() .. ")\n")
  194.         end
  195.         if LowTemperatureTransition:text() ~= "" then
  196.             script:write(FullName .. ", \"LowTemperatureTransition\", " .. "tpt.element(\"" .. LowTemperatureTransition:text() .. "\"))\n")
  197.         end
  198.         if HighPressure:text() ~= "" then
  199.             script:write(FullName .. ", \"HighPressure\", " .. HighPressure:text() .. ")\n")
  200.         end
  201.         if HighPressureTransition:text() ~= "" then
  202.             script:write(FullName .. ", \"HighPressureTransition\", " .. "tpt.element(\"" .. HighPressureTransition:text() .. "\"))\n")
  203.         end
  204.         if LowPressure:text() ~= "" then
  205.             script:write(FullName .. ", \"LowPressure\", " .. LowPressure:text() .. ")\n")
  206.         end
  207.         if LowPressureTransition:text() ~= "" then
  208.             script:write(FullName .. ", \"LowPressureTransition\", " .. "tpt.element(\"" .. LowPressureTransition:text() .. "\"))\n")
  209.         end
  210.  
  211. -- START OF FUNCTION
  212.  
  213.         if Update:checked() then
  214.             script:write("\nlocal function " .. elName:text() .. "_Update(i, x, y, s, n)\n--insert update code here\n")
  215.             script:write("end\n")
  216.             script:write("tpt.element_func(" .. elName:text() .. "_Update" .. ", elements." .. Ident:text() .. "_PT_" .. elName:text() .. ")\n")
  217.         end
  218.         if Graphics:checked() then
  219.             script:write("\nlocal function " .. elName:text() .. "_Graphics(i, r, g, b)\n--insert graphics code here\n")
  220.             script:write("end\n")
  221.             script:write("tpt.graphics_func(" .. elName:text() .. "_Graphics" .. ", elements." .. Ident:text() .. "_PT_" .. elName:text() .. ")")
  222.         end
  223.  
  224.         script:flush()
  225.         interface.closeWindow(SC_UI)
  226.         tpt.message_box("--SCRIPT CREATOR--", "Your script has been created!\n(Check in TPT's folder)")
  227.     end
  228. end
  229.  
  230. tpt.register_keypress(open)
  231.  
  232. SC_UI:addComponent(title)
  233. SC_UI:addComponent(ins)
  234.  
  235. SC_UI:addComponent(scriptname)
  236. SC_UI:addComponent(Ident)
  237. SC_UI:addComponent(elName)
  238. SC_UI:addComponent(Base)
  239. SC_UI:addComponent(Color)
  240. SC_UI:addComponent(MenuVisible)
  241. SC_UI:addComponent(MenuSection)
  242. SC_UI:addComponent(Advection)
  243.  
  244. SC_UI:addComponent(AirDrag)
  245. SC_UI:addComponent(AirLoss)
  246. SC_UI:addComponent(Loss)
  247. SC_UI:addComponent(Collision)
  248. SC_UI:addComponent(Gravity)
  249. SC_UI:addComponent(Diffusion)
  250. SC_UI:addComponent(HotAir)
  251. SC_UI:addComponent(Falldown)
  252.  
  253. SC_UI:addComponent(Flammable)
  254. SC_UI:addComponent(Explosive)
  255. SC_UI:addComponent(Meltable)
  256. SC_UI:addComponent(Hardness)
  257. SC_UI:addComponent(Weight)
  258. SC_UI:addComponent(Temperature)
  259. SC_UI:addComponent(HeatConduct)
  260. SC_UI:addComponent(Description)
  261.  
  262. SC_UI:addComponent(HighTemperature)
  263. SC_UI:addComponent(HighTemperatureTransition)
  264. SC_UI:addComponent(LowTemperature )
  265. SC_UI:addComponent(LowTemperatureTransition)
  266. SC_UI:addComponent(HighPressure )
  267. SC_UI:addComponent(HighPressureTransition)
  268. SC_UI:addComponent(LowPressure)
  269. SC_UI:addComponent(LowPressureTransition)
  270.  
  271. SC_UI:addComponent(State)
  272. SC_UI:addComponent(Properties)
  273.  
  274. SC_UI:addComponent(Create)
  275. SC_UI:addComponent(Close)
  276. SC_UI:addComponent(Reset)
  277. SC_UI:addComponent(Update)
  278. SC_UI:addComponent(Graphics)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement