xXm0dzXx

Game Sketch

Nov 4th, 2012
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. local x,y = term.getSize()
  2. local programName = "new"
  3. local selectedWorkspaceObject = "Game"
  4. local workspace = {
  5. ["Game"] = {
  6. ["Folder"] = true,
  7. },
  8. }
  9.  
  10. local dahObjawcts = {
  11. [2] = "Game",
  12. }
  13.  
  14. function iClicked5( posX, posY )
  15. if posX > x-15 then
  16. if dahObjawcts[posY] then
  17. return dahObjawcts[posY]
  18. end
  19. end
  20. return false
  21. end
  22.  
  23. local scroll = 1
  24.  
  25. local nMenuItem = 1
  26.  
  27. local tArgs = { ... }
  28. if tArgs[1] then
  29. programName = tArgs
  30. end
  31.  
  32. local function cPrint(text)
  33. x2,y2 = term.getCursorPos()
  34. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  35. write(text.. "\n")
  36. end
  37. term.clear()
  38.  
  39. function addObject( path, name, isFolder )
  40. path[name] = {
  41. ["Folder"] = isFolder,
  42. }
  43. end
  44.  
  45. function renderExplorer()
  46.  
  47. dahObjawcts = {}
  48. dahObjawcts[2] = "Game"
  49.  
  50. term.setCursorPos(x-10, 1)
  51. write("Explorer")
  52. local i = 1
  53. function list( path, between )
  54. for k,v in pairs( path ) do
  55. if k ~= "Folder" then
  56. term.setCursorPos(x-15, 1+i)
  57. if selectedWorkspaceObject == (between.. k) then
  58. term.setBackgroundColour( colors.lime )
  59. else
  60. term.setBackgroundColour( colors.lightGray )
  61. end
  62. write( " " )
  63. term.setCursorPos(x-15, 1+i)
  64. write( between.. k )
  65. dahObjawcts[1+i] = between.. k
  66. i = i+1
  67. if path[k]["Folder"] then
  68. list( path[k], between.. "-- " )
  69. end
  70. end
  71. end
  72. end
  73.  
  74. list( workspace, "" )
  75. term.setBackgroundColour( colors.lightBlue )
  76. for i=2,y do
  77. if i == y then
  78. term.setBackgroundColour( colors.gray )
  79. for ia=x-15,x do
  80. term.setCursorPos(ia,i)
  81. write(" ")
  82. end
  83. else
  84. term.setCursorPos(x, i)
  85. write(" ")
  86. end
  87. end
  88. term.setCursorPos(x-10, y)
  89. write("Presets")
  90. term.setCursorPos(x, 1+scroll)
  91. term.setBackgroundColour( colors.blue )
  92. write("=")
  93.  
  94. end
  95.  
  96. function renderMenu()
  97. term.setCursorPos(1,2)
  98. term.setBackgroundColour( colors.gray )
  99. if nMenuItem == 1 then
  100. write("Insert -[Player]Object Folder ")
  101. elseif nMenuItem == 2 then
  102. write("Insert - Player[Object]Folder ")
  103. elseif nMenuItem == 3 then
  104. write("Insert - Player Object[Folder]")
  105. end
  106. end
  107.  
  108. function drawWorkspace()
  109. for i=1,x do
  110. for z=1,y do
  111. paintutils.drawPixel( i, z, colors.white )
  112. end
  113.  
  114. paintutils.drawPixel( i, 1, colors.lightGray )
  115. paintutils.drawPixel( i, 2, colors.gray )
  116. paintutils.drawPixel( i, y, colors.lightGray )
  117.  
  118. for z=1,y do
  119. for iz=x-15,x do
  120. paintutils.drawPixel( iz, z, colors.lightGray )
  121. end
  122. paintutils.drawPixel( x-16, z, colors.gray )
  123. end
  124.  
  125. for iz=x-15,x do
  126. paintutils.drawPixel( iz, 1, colors.gray )
  127. end
  128. end
  129.  
  130. term.setBackgroundColour( colors.lightGray )
  131. term.setTextColour( colors.black )
  132. term.setCursorPos(1,1)
  133. write("GameSketch v1.0 - " ..programName)
  134. term.setCursorPos(1,y)
  135. write( "Editing" )
  136.  
  137. renderMenu()
  138.  
  139. renderExplorer()
  140. end
  141.  
  142. addObject( workspace["Game"], "Object_1", false)
  143. drawWorkspace()
  144.  
  145. while true do
  146. local event, key, keyX, keyY = os.pullEvent()
  147. if event == "key" then
  148. if key == keys.left then
  149. if nMenuItem ~= 1 then
  150. nMenuItem = nMenuItem -1
  151. renderMenu()
  152. end
  153. elseif key == keys.right then
  154. if nMenuItem ~= 3 then
  155. nMenuItem = nMenuItem +1
  156. renderMenu()
  157. end
  158. elseif key == keys.enter then
  159. if nMenuItem == 1 then
  160. local name = "Player"
  161. local nameType = 1
  162. while workspace["Game"][name] do
  163. name = "Player_" ..nameType
  164. nameType = nameType +1
  165. end
  166. addObject( workspace["Game"], name, false )
  167. elseif nMenuItem == 2 then
  168. local name = "Object"
  169. local nameType = 1
  170. while workspace["Game"][name] do
  171. name = "Object_" ..nameType
  172. nameType = nameType +1
  173. end
  174. addObject( workspace["Game"], name, false )
  175. elseif nMenuItem == 3 then
  176. local name = "Folder"
  177. local nameType = 1
  178. while workspace["Game"][name] do
  179. name = "Folder_" ..nameType
  180. nameType = nameType +1
  181. end
  182. addObject( workspace["Game"], name, true )
  183. end
  184.  
  185. renderExplorer()
  186. end
  187. elseif event == "mouse_click" then
  188. if key == 1 then
  189. if iClicked5( keyX, keyY ) then
  190. selectedWorkspaceObject = iClicked5( keyX, keyY )
  191. renderExplorer()
  192. end
  193. end
  194. end
  195. end
Advertisement
Add Comment
Please, Sign In to add comment