SHOW:
|
|
- or go back to the newest paste.
| 1 | os.loadAPI("/tcg/fw")
| |
| 2 | ||
| 3 | cards = {fw.newCard("", "", "noimage")}
| |
| 4 | selectedCard = 1 | |
| 5 | ||
| 6 | function paintimage(card, path, imagebackgroundcolor) | |
| 7 | if imagebackgroundcolor then | |
| 8 | local file = io.open("/tcg/cards/images/"..path, "w")
| |
| 9 | if file then | |
| 10 | local c = imagebackgroundcolor | |
| 11 | for i = 1, fw.imageH do | |
| 12 | local line = "" | |
| 13 | for q = 1, fw.imageW do | |
| 14 | line = line..c | |
| 15 | end | |
| 16 | file:write(string.sub(line, 1, fw.imageW).."\n") | |
| 17 | end | |
| 18 | file:close() | |
| 19 | end | |
| 20 | end | |
| 21 | ||
| 22 | shell.run("paint", "/tcg/cards/images/"..path)
| |
| 23 | card.image = path | |
| 24 | return card | |
| 25 | end | |
| 26 | ||
| 27 | function editfunc(name) | |
| 28 | if not fs.exists("/tcg/cards/scripts/"..name) then
| |
| 29 | local file = io.open("/tcg/cards/scripts/"..name, "w")
| |
| 30 | if file then | |
| 31 | file:write("--[[\n")
| |
| 32 | file:write("\"action\" is fired when the card is put down on a deck\n")
| |
| 33 | file:write("arguments:\n")
| |
| 34 | file:write("1: the card table\n")
| |
| 35 | file:write("2: deck on which the card was played\n")
| |
| 36 | file:write("3: the game table, contains the deck tables\n")
| |
| 37 | file:write("\n")
| |
| 38 | file:write("\"update\" is fired when the card is updated\n")
| |
| 39 | file:write("arguments:\n")
| |
| 40 | file:write("1: the card table\n")
| |
| 41 | file:write("2: event\n")
| |
| 42 | file:write("3: event var 1\n")
| |
| 43 | file:write("4: event var 2\n")
| |
| 44 | file:write("5: event var 3\n")
| |
| 45 | file:write("6: the game table, contains the deck tables\n")
| |
| 46 | file:write("]]")
| |
| 47 | file:write("\n")
| |
| 48 | file:write("function action(self, deck, game)\n")
| |
| 49 | file:write("end\n")
| |
| 50 | file:write("\n")
| |
| 51 | file:write("function update(self, event, var1, var2, var3, game)\n")
| |
| 52 | file:write("end\n")
| |
| 53 | file:close() | |
| 54 | end | |
| 55 | end | |
| 56 | shell.run("edit", "/tcg/cards/scripts/"..name)
| |
| 57 | end | |
| 58 | ||
| 59 | function delcard() | |
| 60 | if #cards>1 then | |
| 61 | table.remove(cards, selectedCard) | |
| 62 | if not cards[selectedCard] then | |
| 63 | if cards[selectedCard+1] then | |
| 64 | selectedCard = selectedCard+1 | |
| 65 | else | |
| 66 | selectedCard = selectedCard-1 | |
| 67 | end | |
| 68 | end | |
| 69 | end | |
| 70 | end | |
| 71 | ||
| 72 | function loadCard() | |
| 73 | input = fw.text( | |
| 74 | "filename", | |
| 75 | function(name) | |
| 76 | local loaded = fw.loadCard("/saves/"..name)
| |
| 77 | if loaded then cards[selectedCard] = loaded end | |
| 78 | end | |
| 79 | ) | |
| 80 | end | |
| 81 | ||
| 82 | function copycard() | |
| 83 | local card = cards[selectedCard] | |
| 84 | table.insert( | |
| 85 | cards, | |
| 86 | fw.newCard( | |
| 87 | card.title, | |
| 88 | card.description, | |
| 89 | card.image | |
| 90 | ) | |
| 91 | ) | |
| 92 | selectedCard = #cards | |
| 93 | end | |
| 94 | ||
| 95 | function newcard() | |
| 96 | cards[#cards+1] = fw.newCard("", "", "noimage")
| |
| 97 | selectedCard=#cards | |
| 98 | end | |
| 99 | ||
| 100 | function initelements() | |
| 101 | elements = {
| |
| 102 | title = fw.button( | |
| 103 | fw.cardX+1, fw.cardY+1, fw.cardW-2, 1, "title", | |
| 104 | "blue", "blue", | |
| 105 | change.title, | |
| 106 | true | |
| 107 | ), | |
| 108 | description = fw.button( | |
| 109 | fw.cardX+1, fw.cardY+fw.cardH-4, fw.imageW, 3, "description", | |
| 110 | "blue", "blue", | |
| 111 | change.description, | |
| 112 | true | |
| 113 | ), | |
| 114 | image = fw.button( | |
| 115 | fw.cardX+1, fw.cardY+3, fw.imageW, fw.imageH, "image", | |
| 116 | "blue", "blue", | |
| 117 | change.image, | |
| 118 | true | |
| 119 | ), | |
| 120 | newimage = fw.button( | |
| 121 | fw.cardX+1, fw.cardY+3, fw.imageW, fw.imageH, "paint", | |
| 122 | "blue", "blue", | |
| 123 | change.newimage, | |
| 124 | true, | |
| 125 | 2 | |
| 126 | ), | |
| 127 | save = fw.button( | |
| 128 | 11, fw.winH-2, nil, 2, "save card", | |
| 129 | "green", "lime", | |
| 130 | function() | |
| 131 | fw.saveCard(card, "saves/"..card.title) | |
| 132 | end | |
| 133 | ), | |
| 134 | savedeck = fw.button( | |
| 135 | 11, fw.winH, nil, 1, "save deck", | |
| 136 | "lime", "green", | |
| 137 | function() | |
| 138 | input = fw.text( | |
| 139 | "filename", | |
| 140 | function(name) | |
| 141 | fw.saveCard(cards, "packs/"..name) | |
| 142 | end | |
| 143 | ) | |
| 144 | end | |
| 145 | ), | |
| 146 | load = fw.button( | |
| 147 | 1, fw.winH-2, 9, 1, "load card", | |
| 148 | "blue", "lightBlue", | |
| 149 | loadCard | |
| 150 | ), | |
| 151 | loaddeck = fw.button( | |
| 152 | 1, fw.winH-1, 9, 1, "load deck", | |
| 153 | "lightBlue", "blue", | |
| 154 | function() | |
| 155 | input = fw.text( | |
| 156 | "filename", | |
| 157 | function(name) | |
| 158 | loaded = fw.loadCard("packs/"..name)
| |
| 159 | if loaded then cards = loaded end | |
| 160 | selectedCard = math.ceil(#cards/2) | |
| 161 | end | |
| 162 | ) | |
| 163 | end | |
| 164 | ), | |
| 165 | whatload = fw.button( | |
| 166 | 1, fw.winH, 9, 1, "cards", | |
| 167 | "cyan", "blue", | |
| 168 | function() | |
| 169 | term.setBackgroundColor(colors.lightGray) | |
| 170 | term.clear() | |
| 171 | paintutils.drawFilledBox(1, 1, fw.winW, 3, colors.cyan) | |
| 172 | paintutils.drawFilledBox(1, fw.winH-3, fw.winW, fw.winH, colors.cyan) | |
| 173 | term.setTextColor(colors.white) | |
| 174 | term.setCursorPos(1, 2) | |
| 175 | textutils.slowWrite("These Cards are aviable to be loaded in the editor:", 220)
| |
| 176 | term.setCursorPos(1, 6) | |
| 177 | term.setBackgroundColor(colors.lightGray) | |
| 178 | textutils.pagedTabulate(fs.list("/tcg/cards/saves"))
| |
| 179 | term.setTextColor(colors.white) | |
| 180 | term.setCursorPos(1, fw.winH-1) | |
| 181 | term.setBackgroundColor(colors.cyan) | |
| 182 | print("Press any key to get back to the editor!")
| |
| 183 | os.pullEvent("key")
| |
| 184 | end | |
| 185 | ), | |
| 186 | delete = fw.button( | |
| 187 | 23, fw.winH-2, 8, 2, "delete", | |
| 188 | "red", "orange", | |
| 189 | delcard | |
| 190 | ), | |
| 191 | deletesave = fw.button( | |
| 192 | 23, fw.winH, 8, 1, "delsave", | |
| 193 | "orange", "yellow", | |
| 194 | function() | |
| 195 | input = fw.text( | |
| 196 | "cardname", | |
| 197 | function(name) | |
| 198 | input2 = fw.text( | |
| 199 | "delete"..name.."?!", | |
| 200 | function(name) | |
| 201 | if name == "yes" or name=="y" or name == "Yes" or name == "ja" then | |
| 202 | fs.delete("/tcg/cards/saves/"..name)
| |
| 203 | end | |
| 204 | end | |
| 205 | ) | |
| 206 | end | |
| 207 | ) | |
| 208 | input = input2 | |
| 209 | end | |
| 210 | ), | |
| 211 | new = fw.button( | |
| 212 | 32, fw.winH-2, 5, 2, "new", | |
| 213 | "gray", "lightGray", | |
| 214 | newcard | |
| 215 | ), | |
| 216 | copy = fw.button( | |
| 217 | 32, fw.winH, 5, 1, "copy", | |
| 218 | "lightGray", "gray", | |
| 219 | function() | |
| 220 | cards[#cards+1] = fw.newCard("", "", "noimage")
| |
| 221 | selectedCard=#cards | |
| 222 | end | |
| 223 | ), | |
| 224 | exit = fw.button( | |
| 225 | 38, fw.winH-2, nil, 3, "exit", | |
| 226 | "yellow", "orange", | |
| 227 | function() | |
| 228 | os.unloadAPI(fw) | |
| 229 | fw.exit() | |
| 230 | end | |
| 231 | ), | |
| 232 | script = fw.button( | |
| 233 | 45, fw.winH-2, nil, 3, "script", | |
| 234 | "white", "lightGray", | |
| 235 | function() | |
| 236 | if not card.script then | |
| 237 | input = fw.text( | |
| 238 | "filename", | |
| 239 | function(name) | |
| 240 | card.script = name | |
| 241 | editfunc(name) | |
| 242 | end | |
| 243 | ) | |
| 244 | else | |
| 245 | editfunc(card.script) | |
| 246 | end | |
| 247 | end | |
| 248 | ), | |
| 249 | right = fw.button( | |
| 250 | fw.cardX+fw.cardW+1, fw.cardY, fw.sideCards*fw.cardW, 12, ">", | |
| 251 | "blue", "blue", | |
| 252 | function() | |
| 253 | if cards[selectedCard+1] then | |
| 254 | selectedCard = selectedCard+1 | |
| 255 | end | |
| 256 | end, | |
| 257 | true | |
| 258 | ), | |
| 259 | left = fw.button( | |
| 260 | fw.cardX-fw.sideCards*fw.cardW-fw.cardW+5, fw.cardY, fw.sideCards*fw.cardW+5, 12, "<", | |
| 261 | "blue", "blue", | |
| 262 | function() | |
| 263 | if cards[selectedCard-1] then | |
| 264 | selectedCard = selectedCard-1 | |
| 265 | end | |
| 266 | end, | |
| 267 | true | |
| 268 | ), | |
| 269 | help = fw.button( | |
| 270 | fw.winW-1, 2, 2, 2, "??", | |
| 271 | "green", "lime", | |
| 272 | function() | |
| 273 | if fs.exists("/tcg/editor/manual") then
| |
| 274 | local id = multishell.launch({}, "/tcg/editor/manual")
| |
| 275 | multishell.setFocus(id) | |
| 276 | end | |
| 277 | end | |
| 278 | ) | |
| 279 | } | |
| 280 | end | |
| 281 | ||
| 282 | change = {
| |
| 283 | title = function() | |
| 284 | input = fw.text( | |
| 285 | "insert title", | |
| 286 | function(name) | |
| 287 | card.title = name | |
| 288 | end, | |
| 289 | card.title | |
| 290 | ) | |
| 291 | end, | |
| 292 | description = function() | |
| 293 | input = fw.text( | |
| 294 | "insert description", | |
| 295 | function(name) | |
| 296 | card.description = name | |
| 297 | end, | |
| 298 | card.description | |
| 299 | ) | |
| 300 | end, | |
| 301 | image = function() | |
| 302 | input = fw.text( | |
| 303 | "insert filename", | |
| 304 | function(name) | |
| 305 | if fs.exists("/tcg/cards/images/"..name) and #name>0 then
| |
| 306 | card.image = name | |
| 307 | cardimage = paintutils.loadImage(card.image) | |
| 308 | end | |
| 309 | end, | |
| 310 | card.image | |
| 311 | ) | |
| 312 | end, | |
| 313 | newimage = function(name) | |
| 314 | if card.image == "noimage" then | |
| 315 | input = fw.text( | |
| 316 | "image name", | |
| 317 | function(name) | |
| 318 | paintpath = name | |
| 319 | if #paintpath>0 then | |
| 320 | if fs.exists("/tcg/cards/images/"..paintpath) then
| |
| 321 | card = paintimage(card, paintpath) | |
| 322 | else | |
| 323 | input2 = fw.text( | |
| 324 | "color code", | |
| 325 | function(col) | |
| 326 | card = paintimage(card, paintpath, col) | |
| 327 | end | |
| 328 | ) | |
| 329 | end | |
| 330 | end | |
| 331 | end | |
| 332 | ) | |
| 333 | else | |
| 334 | paintimage(card, card.image) | |
| 335 | end | |
| 336 | end | |
| 337 | } | |
| 338 | ||
| 339 | while true do | |
| 340 | --draw stuff | |
| 341 | fw.winW, fw.winH = term.getSize() | |
| 342 | initelements() | |
| 343 | local textinput = {inp = input, inp2 = input2}
| |
| 344 | card = cards[selectedCard] | |
| 345 | fw.draw(elements, "black") | |
| 346 | term.setBackgroundColor(colors.gray) | |
| 347 | paintutils.drawLine(1, 1, fw.winW, 1) | |
| 348 | term.setTextColor(colors.white) | |
| 349 | term.setCursorPos(1, 1) | |
| 350 | print("Editing '"..card.title.."', card number: "..selectedCard)
| |
| 351 | ||
| 352 | for i = -4, 0 do | |
| 353 | if cards[selectedCard+i] then | |
| 354 | fw.drawCard(fw.cardX+5*i, fw.cardY-1*i/2, cards[selectedCard+i]) | |
| 355 | end | |
| 356 | end | |
| 357 | for i = -4, 0 do | |
| 358 | if cards[selectedCard-i] then | |
| 359 | fw.drawCard(fw.cardX-5*i, fw.cardY-1*i/2, cards[selectedCard-i]) | |
| 360 | end | |
| 361 | end | |
| 362 | fw.drawCard(fw.cardX, fw.cardY, card) | |
| 363 | ||
| 364 | term.setCursorPos(fw.winW-15, 1) | |
| 365 | term.blit("0123456789abcdef", "8ea91da87b297517", "0123456789abcdef")
| |
| 366 | ||
| 367 | fw.draw(textinput) | |
| 368 | ||
| 369 | --update fw | |
| 370 | local event, var1, var2, var3 = os.pullEventRaw() | |
| 371 | if event == "key" and input.title == "" then | |
| 372 | if var1 == keys.right then | |
| 373 | if selectedCard~=#cards then selectedCard=selectedCard+1 end | |
| 374 | elseif var1 == keys.left then | |
| 375 | if selectedCard~=1 then selectedCard=selectedCard-1 end | |
| 376 | elseif var1 == keys.up then | |
| 377 | change.title() | |
| 378 | elseif var1 == keys.down then | |
| 379 | change.description() | |
| 380 | elseif var1 == keys.s then | |
| 381 | fw.saveCard(card, "saves/"..card.title) | |
| 382 | elseif var1 == keys.backspace or var1 == keys.d or var1 == keys.delete then | |
| 383 | delcard() | |
| 384 | elseif var1 == keys.c then | |
| 385 | copycard() | |
| 386 | elseif var1 == keys.l then | |
| 387 | loadCard() | |
| 388 | elseif var1 == keys.e then | |
| 389 | fw.exit() | |
| 390 | elseif var1 == keys.n then | |
| 391 | newcard() | |
| 392 | end | |
| 393 | end | |
| 394 | fw.update(textinput, event, var1, var2, var3) | |
| 395 | fw.update(elements, event, var1, var2, var3) | |
| 396 | if not textinput.inp then | |
| 397 | input = fw.button(1, 1, 1, 1, "", nil, nil, nil, true) | |
| 398 | end | |
| 399 | if not textinput.inp2 then | |
| 400 | input2 = fw.button(1, 1, 1, 1, "", nil, nil, nil, true) | |
| 401 | end | |
| 402 | end |