SHOW:
|
|
- or go back to the newest paste.
| 1 | -- cxi's Element Creator | |
| 2 | -- Version 1.0 August 12 2016 | |
| 3 | -- This code is released under the MIT license | |
| 4 | ||
| 5 | function round(num, dp) | |
| 6 | local mult = 10^(dp or 0) | |
| 7 | return math.floor(num * mult + 0.5) / mult | |
| 8 | end | |
| 9 | ||
| 10 | local element = elem.allocate("CXI", "ELEM")
| |
| 11 | ||
| 12 | elem.element(element, elem.element(elem.DEFAULT_PT_DMND)) | |
| 13 | elem.property(element, "Name", "ELEM") | |
| 14 | elem.property(element, "Colour", 0xFFFFFF) | |
| 15 | elem.property(element, "Description", "Element created using cxi's element creator. Press N to open.") | |
| 16 | elem.property(element, "MenuSection", elem.SC_SPECIAL) | |
| 17 | ||
| 18 | local width = 600 | |
| 19 | local height = 342 | |
| 20 | ||
| 21 | local exportwidth = 570 | |
| 22 | local exportheight = 88 | |
| 23 | ||
| 24 | local window = Window:new(14, 38, width, height) | |
| 25 | local exportwindow = Window:new(29, 165, exportwidth, exportheight) | |
| 26 | ||
| 27 | local clrlabel = Label:new(270, 316, 32, 16, "Color:") | |
| 28 | window:addComponent(clrlabel) | |
| 29 | local colortext = Textbox:new(306, 316, 50, 16, "ffffff", "") | |
| 30 | window:addComponent(colortext) | |
| 31 | ||
| 32 | local y = 30 | |
| 33 | ||
| 34 | local advlabel = Label:new(10, y, width / 2 - 20, 16, "Advection - how much air movement affects a particle.") | |
| 35 | window:addComponent(advlabel) | |
| 36 | local advectiontext = Textbox:new(10, y + 20, width / 2 - 20, 16, "0.4", "") | |
| 37 | window:addComponent(advectiontext) | |
| 38 | y = y + 40 | |
| 39 | ||
| 40 | local adrlabel = Label:new(10, y, width / 2 - 20, 16, "AirDrag - how much air a particle moves when moving.") | |
| 41 | window:addComponent(adrlabel) | |
| 42 | local airdragtext = Textbox:new(10, y + 20, width / 2 - 20, 16, "0.01", "") | |
| 43 | window:addComponent(airdragtext) | |
| 44 | y = y + 40 | |
| 45 | ||
| 46 | local allabel = Label:new(10, y, width / 2 - 20, 16, "AirLoss - how much a particle slows down moving air.") | |
| 47 | window:addComponent(allabel) | |
| 48 | local airlosstext = Textbox:new(10, y + 20, width / 2 - 20, 16, "0.94", "") | |
| 49 | window:addComponent(airlosstext) | |
| 50 | y = y + 40 | |
| 51 | ||
| 52 | local llabel = Label:new(10, y, width / 2 - 20, 16, "Loss - how much the speed a particle retains each frame.") | |
| 53 | window:addComponent(llabel) | |
| 54 | local losstext = Textbox:new(10, y + 20, width / 2 - 20, 16, "0.95", "") | |
| 55 | window:addComponent(losstext) | |
| 56 | y = y + 40 | |
| 57 | ||
| 58 | local collabel = Label:new(10, y, width / 2 - 20, 16, "Collision - how a particle moves when it collides.") | |
| 59 | window:addComponent(collabel) | |
| 60 | local collisiontext = Textbox:new(10, y + 20, width / 2 - 20, 16, "-0.1", "") | |
| 61 | window:addComponent(collisiontext) | |
| 62 | y = y + 40 | |
| 63 | ||
| 64 | local grvlabel = Label:new(10, y, width / 2 - 20, 16, "Gravity - how fast a particle falls.") | |
| 65 | window:addComponent(grvlabel) | |
| 66 | local gravitytext = Textbox:new(10, y + 20, width / 2 - 20, 16, "-0.1", "") | |
| 67 | window:addComponent(gravitytext) | |
| 68 | y = y + 40 | |
| 69 | ||
| 70 | local diflabel = Label:new(10, y, width / 2 - 20, 16, "Diffusion - how much a particle wiggles.") | |
| 71 | window:addComponent(diflabel) | |
| 72 | local diffusiontext = Textbox:new(10, y + 20, width / 2 - 20, 16, "0", "") | |
| 73 | window:addComponent(diffusiontext) | |
| 74 | y = 30 | |
| 75 | ||
| 76 | local htalabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "HotAir - how much a particle increases the pressure by.") | |
| 77 | window:addComponent(htalabel) | |
| 78 | local hotairtext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 79 | window:addComponent(hotairtext) | |
| 80 | y = y + 40 | |
| 81 | ||
| 82 | local explabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "Explosive - 0: none, 1: fire, 2: pressure > 2.5 or fire.") | |
| 83 | window:addComponent(explabel) | |
| 84 | local explosivetext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 85 | window:addComponent(explosivetext) | |
| 86 | y = y + 40 | |
| 87 | ||
| 88 | local fllabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "Flammable - how well the element burns.") | |
| 89 | window:addComponent(fllabel) | |
| 90 | local flammabletext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 91 | window:addComponent(flammabletext) | |
| 92 | y = y + 40 | |
| 93 | ||
| 94 | local hdlabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "Hardness - how quickly ACID dissolves the element.") | |
| 95 | window:addComponent(hdlabel) | |
| 96 | local hardnesstext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 97 | window:addComponent(hardnesstext) | |
| 98 | y = y + 40 | |
| 99 | ||
| 100 | local wtlabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "Weight - how heavy the element is.") | |
| 101 | window:addComponent(wtlabel) | |
| 102 | local weighttext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 103 | window:addComponent(weighttext) | |
| 104 | y = y + 40 | |
| 105 | ||
| 106 | local hclabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "Heat conductivity - 0 to 255.") | |
| 107 | window:addComponent(hclabel) | |
| 108 | local heatconducttext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 109 | window:addComponent(heatconducttext) | |
| 110 | y = y + 40 | |
| 111 | ||
| 112 | local itlabel = Label:new(width / 2 + 10, y, width / 2 - 20, 16, "Initial temperature in Kelvin.") | |
| 113 | window:addComponent(itlabel) | |
| 114 | local temperaturetext = Textbox:new(width / 2 + 10, y + 20, width / 2 - 20, 16, "0", "") | |
| 115 | window:addComponent(temperaturetext) | |
| 116 | ||
| 117 | local function updateproperties(sender) | |
| 118 | elem.property(element, "Color", tonumber(colortext:text():lower(), 16)) | |
| 119 | elem.property(element, "Advection", tonumber(advectiontext:text())) | |
| 120 | elem.property(element, "AirDrag", tonumber(airdragtext:text())) | |
| 121 | elem.property(element, "AirLoss", tonumber(airlosstext:text())) | |
| 122 | elem.property(element, "Loss", tonumber(losstext:text())) | |
| 123 | elem.property(element, "Collision", tonumber(collisiontext:text())) | |
| 124 | elem.property(element, "Gravity", tonumber(gravitytext:text())) | |
| 125 | elem.property(element, "Diffusion", tonumber(diffusiontext:text())) | |
| 126 | elem.property(element, "HotAir", tonumber(hotairtext:text())) | |
| 127 | elem.property(element, "Explosive", tonumber(explosivetext:text())) | |
| 128 | elem.property(element, "Flammable", tonumber(flammabletext:text())) | |
| 129 | elem.property(element, "Hardness", tonumber(hardnesstext:text())) | |
| 130 | elem.property(element, "Weight", tonumber(weighttext:text())) | |
| 131 | elem.property(element, "HeatConduct", tonumber(heatconducttext:text())) | |
| 132 | elem.property(element, "Temperature", tonumber(temperaturetext:text())) | |
| 133 | end | |
| 134 | ||
| 135 | colortext:onTextChanged(updateproperties) | |
| 136 | advectiontext:onTextChanged(updateproperties) | |
| 137 | airdragtext:onTextChanged(updateproperties) | |
| 138 | airlosstext:onTextChanged(updateproperties) | |
| 139 | losstext:onTextChanged(updateproperties) | |
| 140 | collisiontext:onTextChanged(updateproperties) | |
| 141 | gravitytext:onTextChanged(updateproperties) | |
| 142 | diffusiontext:onTextChanged(updateproperties) | |
| 143 | hotairtext:onTextChanged(updateproperties) | |
| 144 | explosivetext:onTextChanged(updateproperties) | |
| 145 | flammabletext:onTextChanged(updateproperties) | |
| 146 | hardnesstext:onTextChanged(updateproperties) | |
| 147 | weighttext:onTextChanged(updateproperties) | |
| 148 | heatconducttext:onTextChanged(updateproperties) | |
| 149 | temperaturetext:onTextChanged(updateproperties) | |
| 150 | ||
| 151 | local x = 10 | |
| 152 | local w = 48 | |
| 153 | local buttons = {}
| |
| 154 | ||
| 155 | local solidbutton = Button:new(x, 316, w, 16, "Solid") | |
| 156 | window:addComponent(solidbutton) | |
| 157 | x = x + w - 1 | |
| 158 | buttons["Solid"] = solidbutton | |
| 159 | ||
| 160 | local powderbutton = Button:new(x, 316, w, 16, "Powder") | |
| 161 | window:addComponent(powderbutton) | |
| 162 | x = x + w - 1 | |
| 163 | buttons["Powder"] = powderbutton | |
| 164 | ||
| 165 | local liquidbutton = Button:new(x, 316, w, 16, "Liquid") | |
| 166 | window:addComponent(liquidbutton) | |
| 167 | x = x + w - 1 | |
| 168 | buttons["Liquid"] = liquidbutton | |
| 169 | ||
| 170 | local gasbutton = Button:new(x, 316, w, 16, "Gas") | |
| 171 | window:addComponent(gasbutton) | |
| 172 | x = x + w - 1 | |
| 173 | buttons["Gas"] = gasbutton | |
| 174 | ||
| 175 | local energybutton = Button:new(x, 316, w, 16, "Energy") | |
| 176 | window:addComponent(energybutton) | |
| 177 | x = x + w - 1 | |
| 178 | buttons["Energy"] = energybutton | |
| 179 | ||
| 180 | local function settype(sender) | |
| 181 | if sender:text() == solidbutton:text() then | |
| 182 | elem.property(element, "Properties", elem.TYPE_SOLID) | |
| 183 | elem.property(element, "Falldown", 0) | |
| 184 | end | |
| 185 | if sender:text() == powderbutton:text() then | |
| 186 | elem.property(element, "Properties", elem.TYPE_PART) | |
| 187 | elem.property(element, "Falldown", 1) | |
| 188 | end | |
| 189 | if sender:text() == liquidbutton:text() then | |
| 190 | elem.property(element, "Properties", elem.TYPE_LIQUID) | |
| 191 | elem.property(element, "Falldown", 2) | |
| 192 | end | |
| 193 | if sender:text() == gasbutton:text() then | |
| 194 | elem.property(element, "Properties", elem.TYPE_GAS) | |
| 195 | elem.property(element, "Falldown", 0) | |
| 196 | end | |
| 197 | if sender:text() == energybutton:text() then | |
| 198 | elem.property(element, "Properties", elem.TYPE_ENERGY) | |
| 199 | elem.property(element, "Falldown", 0) | |
| 200 | end | |
| 201 | for i, button in pairs(buttons) do | |
| 202 | if string.find(sender:text(), i) then | |
| 203 | button:text("[" .. i .. "]")
| |
| 204 | else | |
| 205 | button:text(i) | |
| 206 | end | |
| 207 | end | |
| 208 | end | |
| 209 | ||
| 210 | solidbutton:action(settype) | |
| 211 | powderbutton:action(settype) | |
| 212 | liquidbutton:action(settype) | |
| 213 | gasbutton:action(settype) | |
| 214 | energybutton:action(settype) | |
| 215 | ||
| 216 | local function loadelement(sender) | |
| 217 | local e = assert(loadstring("return elem.DEFAULT_PT_" .. sender:text():upper()), nil)()
| |
| 218 | if e ~= nil then | |
| 219 | local type = bit.band(elem.property(e, "Properties"), 31) | |
| 220 | elem.property(element, "Properties", type) | |
| 221 | if type == elem.TYPE_SOLID then | |
| 222 | settype(solidbutton) | |
| 223 | elseif type == elem.TYPE_PART then | |
| 224 | settype(powderbutton) | |
| 225 | elseif type == elem.TYPE_LIQUID then | |
| 226 | settype(liquidbutton) | |
| 227 | elseif type == elem.TYPE_GAS then | |
| 228 | settype(gasbutton) | |
| 229 | elseif type == elem.TYPE_ENERGY then | |
| 230 | settype(energybutton) | |
| 231 | end | |
| 232 | elem.property(element, "Falldown", elem.property(e, "Falldown")) | |
| 233 | colortext:text(string.format("%x", elem.property(e, "Color")))
| |
| 234 | advectiontext:text(round(elem.property(e, "Advection"), 7)) | |
| 235 | airdragtext:text(round(elem.property(e, "AirDrag"), 7)) | |
| 236 | airlosstext:text(round(elem.property(e, "AirLoss"), 7)) | |
| 237 | losstext:text(round(elem.property(e, "Loss"), 7)) | |
| 238 | collisiontext:text(round(elem.property(e, "Collision"), 7)) | |
| 239 | gravitytext:text(round(elem.property(e, "Gravity"), 7)) | |
| 240 | diffusiontext:text(round(elem.property(e, "Diffusion"), 7)) | |
| 241 | hotairtext:text(round(elem.property(e, "HotAir"), 7)) | |
| 242 | explosivetext:text(round(elem.property(e, "Explosive"), 0)) | |
| 243 | flammabletext:text(round(elem.property(e, "Flammable"), 0)) | |
| 244 | hardnesstext:text(round(elem.property(e, "Hardness"), 0)) | |
| 245 | weighttext:text(round(elem.property(e, "Weight"), 0)) | |
| 246 | heatconducttext:text(round(elem.property(e, "HeatConduct"), 0)) | |
| 247 | temperaturetext:text(round(elem.property(e, "Temperature"), 2)) | |
| 248 | updateproperties() | |
| 249 | end | |
| 250 | end | |
| 251 | ||
| 252 | local loadlabel = Label:new(10, 10, 180, 16, "Load properties from existing element:") | |
| 253 | window:addComponent(loadlabel) | |
| 254 | local loadtext = Textbox:new(196, 10, 64, 16, "DUST", "") | |
| 255 | loadtext:onTextChanged(loadelement) | |
| 256 | window:addComponent(loadtext) | |
| 257 | ||
| 258 | local function export(sender) | |
| 259 | ui.showWindow(exportwindow) | |
| 260 | end | |
| 261 | ||
| 262 | local exportbutton = Button:new(width - 110, height - 26, 100, 16, "Export code...") | |
| 263 | exportbutton:action(export) | |
| 264 | window:addComponent(exportbutton) | |
| 265 | ||
| 266 | window:onTryExit(function() | |
| 267 | tpt.active_menu(elem.SC_SPECIAL) | |
| 268 | ui.closeWindow(window) | |
| 269 | end) | |
| 270 | ||
| 271 | local namespace = Textbox:new(10, 10, 120, 16, "", "Namespace") | |
| 272 | exportwindow:addComponent(namespace) | |
| 273 | local name = Textbox:new(130, 10, 120, 16, "", "1-4 character name") | |
| 274 | exportwindow:addComponent(name) | |
| 275 | local description = Textbox:new(10, 36, exportwidth - 20, 16, "", "Description") | |
| 276 | exportwindow:addComponent(description) | |
| 277 | local addtemplates = Checkbox:new(10, 62, exportwidth / 2 - 20, 16, "Include templates for update and graphics functions") | |
| 278 | exportwindow:addComponent(addtemplates) | |
| 279 | ||
| 280 | local function exportlua(sender) | |
| 281 | local namespacestr = namespace:text():upper() | |
| 282 | local namestr = name:text():upper() | |
| 283 | ||
| 284 | if namespacestr:gsub("%s+", "") == "" or namestr:gsub("%s+", "") == "" or description:text():gsub("%s+", "") == "" then
| |
| 285 | tpt.message_box("Error", "Missing required fields.")
| |
| 286 | return | |
| 287 | end | |
| 288 | ||
| 289 | local elementconstant = "elem." .. namespacestr .. "_PT_" .. namestr | |
| 290 | local state = "" | |
| 291 | local properties = "" | |
| 292 | ||
| 293 | local type = bit.band(elem.property(element, "Properties"), 31) | |
| 294 | if type == elem.TYPE_SOLID then | |
| 295 | state = "elem.ST_SOLID" | |
| 296 | properties = "elem.TYPE_SOLID" | |
| 297 | elseif type == elem.TYPE_PART then | |
| 298 | state = "elem.ST_SOLID" | |
| 299 | properties = "elem.TYPE_PART" | |
| 300 | elseif type == elem.TYPE_LIQUID then | |
| 301 | state = "elem.ST_LIQUID" | |
| 302 | properties = "elem.TYPE_LIQUID" | |
| 303 | elseif type == elem.TYPE_GAS then | |
| 304 | state = "elem.ST_GAS" | |
| 305 | properties = "elem.TYPE_GAS" | |
| 306 | elseif type == elem.TYPE_ENERGY then | |
| 307 | state = "elem.ST_NONE" | |
| 308 | properties = "elem.TYPE_ENERGY" | |
| 309 | end | |
| 310 | ||
| 311 | local code = string.format([[elem.allocate("%s", "%s")
| |
| 312 | elem.element(%s, elem.element(elem.DEFAULT_PT_DMND)) | |
| 313 | ||
| 314 | elem.property(%s, "Name", "%s") | |
| 315 | elem.property(%s, "Description", "%s") | |
| 316 | elem.property(%s, "Colour", 0x%x) | |
| 317 | elem.property(%s, "MenuVisible", 1) | |
| 318 | elem.property(%s, "MenuSection", SC_SPECIAL) | |
| 319 | ||
| 320 | elem.property(%s, "Advection", %s) | |
| 321 | elem.property(%s, "AirDrag", %s) | |
| 322 | elem.property(%s, "AirLoss", %s) | |
| 323 | elem.property(%s, "Loss", %s) | |
| 324 | elem.property(%s, "Collision", %s) | |
| 325 | elem.property(%s, "Gravity", %s) | |
| 326 | elem.property(%s, "Diffusion", %s) | |
| 327 | elem.property(%s, "HotAir", %s) | |
| 328 | ||
| 329 | elem.property(%s, "Explosive", %s) | |
| 330 | elem.property(%s, "Flammable", %s) | |
| 331 | elem.property(%s, "Hardness", %s) | |
| 332 | elem.property(%s, "Meltable", 0) | |
| 333 | elem.property(%s, "Weight", %s) | |
| 334 | ||
| 335 | elem.property(%s, "HeatConduct", %s) | |
| 336 | elem.property(%s, "Temperature", %s) | |
| 337 | ||
| 338 | elem.property(%s, "Falldown", %s) | |
| 339 | elem.property(%s, "State", %s) | |
| 340 | elem.property(%s, "Properties", %s) | |
| 341 | ||
| 342 | elem.property(%s, "LowPressure", IPL) | |
| 343 | elem.property(%s, "LowPressureTransition", NT) | |
| 344 | elem.property(%s, "HighPressure", IPH) | |
| 345 | elem.property(%s, "HighPressureTransition", NT) | |
| 346 | elem.property(%s, "LowTemperature", ITL) | |
| 347 | elem.property(%s, "LowTemperatureTransition", NT) | |
| 348 | elem.property(%s, "HighTemperature", ITH) | |
| 349 | elem.property(%s, "HighTemperatureTransition", NT)]], namespacestr, namestr, elementconstant, elementconstant, namestr, elementconstant, description:text(), elementconstant, elem.property(element, "Color"), elementconstant, elementconstant, elementconstant, round(elem.property(element, "Advection"), 7), elementconstant, round(elem.property(element, "AirDrag"), 7), elementconstant, round(elem.property(element, "AirLoss"), 7), elementconstant, round(elem.property(element, "Loss"), 7), elementconstant, round(elem.property(element, "Collision"), 7), elementconstant, round(elem.property(element, "Gravity"), 7), elementconstant, round(elem.property(element, "Diffusion"), 7), elementconstant, round(elem.property(element, "HotAir"), 7), elementconstant, round(elem.property(element, "Explosive"), 0), elementconstant, round(elem.property(element, "Flammable"), 0), elementconstant, round(elem.property(element, "Hardness"), 0), elementconstant, elementconstant, round(elem.property(element, "Weight"), 0), elementconstant, round(elem.property(element, "HeatConduct"), 0), elementconstant, round(elem.property(element, "Temperature"), 2), elementconstant, elem.property(element, "Falldown"), elementconstant, state, elementconstant, properties, elementconstant, elementconstant, elementconstant, elementconstant, elementconstant, elementconstant, elementconstant, elementconstant) | |
| 350 | ||
| 351 | if addtemplates:checked() then | |
| 352 | code = code .. string.format([[ | |
| 353 | ||
| 354 | ||
| 355 | function %s_Update(i, x, y, ss, nt) | |
| 356 | -- i: particle index | |
| 357 | -- x, y: particle x, y coords | |
| 358 | end | |
| 359 | elements.property(%s, "Update", %s_Update) | |
| 360 | ||
| 361 | function %s_Graphics(i, colr, colg, colb) | |
| 362 | -- i: particle index | |
| 363 | -- colr, colg, colb: color red, green, and blue channels | |
| 364 | ||
| 365 | -- return cache, pixel mode, | |
| 366 | -- alpha, red, green, blue, | |
| 367 | -- fire alpha, fire red, fire green, fire blue | |
| 368 | return 1, 0x0000001, 255, colr, colg, colb, 0, 0, 0, 0 | |
| 369 | end | |
| 370 | elements.property(%s, "Graphics", %s_Graphics)]], namestr, elementconstant, namestr, namestr, elementconstant, namestr) | |
| 371 | end | |
| 372 | ||
| 373 | file = io.open("scripts/" .. namestr .. ".lua", "w")
| |
| 374 | file:write(code) | |
| 375 | file:close() | |
| 376 | end | |
| 377 | ||
| 378 | local function exportcpp(sender) | |
| 379 | local namestr = name:text():upper() | |
| 380 | ||
| 381 | if namestr:gsub("%s+", "") == "" or description:text():gsub("%s+", "") == "" then
| |
| 382 | tpt.message_box("Error", "Missing required fields.")
| |
| 383 | return | |
| 384 | end | |
| 385 | ||
| 386 | local properties = "" | |
| 387 | ||
| 388 | local type = bit.band(elem.property(element, "Properties"), 31) | |
| 389 | if type == elem.TYPE_SOLID then | |
| 390 | properties = "TYPE_SOLID" | |
| 391 | elseif type == elem.TYPE_PART then | |
| 392 | properties = "TYPE_PART" | |
| 393 | elseif type == elem.TYPE_LIQUID then | |
| 394 | properties = "TYPE_LIQUID" | |
| 395 | elseif type == elem.TYPE_GAS then | |
| 396 | properties = "TYPE_GAS" | |
| 397 | elseif type == elem.TYPE_ENERGY then | |
| 398 | properties = "TYPE_ENERGY" | |
| 399 | end | |
| 400 | ||
| 401 | local code = string.format([[#include "simulation/Elements.h" | |
| 402 | //#TPT-Directive ElementClass Element_%s PT_%s {INSERT ID HERE}
| |
| 403 | Element_%s::Element_%s() | |
| 404 | {
| |
| 405 | Identifier = "DEFAULT_PT_%s"; | |
| 406 | Name = "%s"; | |
| 407 | Colour = PIXPACK(0x%x); | |
| 408 | MenuVisible = 1; | |
| 409 | MenuSection = SC_SPECIAL; | |
| 410 | Enabled = 1; | |
| 411 | ||
| 412 | Advection = %sf; | |
| 413 | AirDrag = %sf * CFDS; | |
| 414 | AirLoss = %s; | |
| 415 | Loss = %sf; | |
| 416 | Collision = %sf; | |
| 417 | Gravity = %sf; | |
| 418 | Diffusion = %sf; | |
| 419 | HotAir = %sf * CFDS; | |
| 420 | Falldown = %s; | |
| 421 | ||
| 422 | Flammable = %s; | |
| 423 | Explosive = %s; | |
| 424 | Meltable = 0; | |
| 425 | Hardness = %s; | |
| 426 | ||
| 427 | Weight = %s; | |
| 428 | ||
| 429 | Temperature = %sf; | |
| 430 | HeatConduct = %s; | |
| 431 | Description = "%s"; | |
| 432 | ||
| 433 | Properties = %s; | |
| 434 | ||
| 435 | LowPressure = IPL; | |
| 436 | LowPressureTransition = NT; | |
| 437 | HighPressure = IPH; | |
| 438 | HighPressureTransition = NT; | |
| 439 | LowTemperature = ITL; | |
| 440 | LowTemperatureTransition = NT; | |
| 441 | HighTemperature = ITH; | |
| 442 | HighTemperatureTransition = NT;]], namestr, namestr, namestr, namestr, namestr, namestr, elem.property(element, "Color"), round(elem.property(element, "Advection"), 7), round(elem.property(element, "AirDrag"), 7), round(elem.property(element, "AirLoss"), 7), round(elem.property(element, "Loss"), 7), round(elem.property(element, "Collision"), 7), round(elem.property(element, "Gravity"), 7), round(elem.property(element, "Diffusion"), 7), round(elem.property(element, "HotAir"), 7), elem.property(element, "Falldown"), round(elem.property(element, "Flammable"), 0), round(elem.property(element, "Explosive"), 0), round(elem.property(element, "Hardness"), 0), round(elem.property(element, "Weight"), 0), round(elem.property(element, "Temperature"), 2), round(elem.property(element, "HeatConduct"), 0), description:text(), properties) | |
| 443 | ||
| 444 | if addtemplates:checked() then | |
| 445 | code = code .. string.format([[ | |
| 446 | ||
| 447 | ||
| 448 | Update = &Element_%s::update; | |
| 449 | Graphics = &Element_%s::graphics;]], namestr, namestr) | |
| 450 | end | |
| 451 | ||
| 452 | code = code .. [[ | |
| 453 | ||
| 454 | }]] | |
| 455 | ||
| 456 | if addtemplates:checked() then | |
| 457 | code = code .. string.format([[ | |
| 458 | ||
| 459 | ||
| 460 | // #define UPDATE_FUNC_ARGS Simulation* sim, int i, int x, int y, int surround_space, int nt, Particle *parts, int pmap[YRES][XRES] | |
| 461 | ||
| 462 | //#TPT-Directive ElementHeader Element_%s static int update(UPDATE_FUNC_ARGS) | |
| 463 | int Element_%s::update(UPDATE_FUNC_ARGS) | |
| 464 | {
| |
| 465 | ||
| 466 | } | |
| 467 | ||
| 468 | // #define GRAPHICS_FUNC_ARGS Renderer *ren, Particle *cpart, int nx, int ny, | |
| 469 | // int *pixel_mode, int* cola, int *colr, int *colg, | |
| 470 | // int *colb, int *firea, int *firer, int *fireg, int *fireb | |
| 471 | ||
| 472 | //#TPT-Directive ElementHeader Element_%s static int graphics(GRAPHICS_FUNC_ARGS) | |
| 473 | int Element_%s::graphics(GRAPHICS_FUNC_ARGS) | |
| 474 | {
| |
| 475 | ||
| 476 | }]], namestr, namestr, namestr, namestr) | |
| 477 | end | |
| 478 | ||
| 479 | code = code .. string.format([[ | |
| 480 | ||
| 481 | ||
| 482 | Element_%s::~Element_%s() {}]], namestr, namestr)
| |
| 483 | ||
| 484 | file = io.open(namestr .. ".cpp", "w") | |
| 485 | file:write(code) | |
| 486 | file:close() | |
| 487 | end | |
| 488 | ||
| 489 | local exportluabutton = Button:new(exportwidth - 110, exportheight - 26, 100, 16, "Export Lua code") | |
| 490 | exportluabutton:action(exportlua) | |
| 491 | exportwindow:addComponent(exportluabutton) | |
| 492 | local exportcppbutton = Button:new(exportwidth - 220, exportheight - 26, 100, 16, "Export C++ code") | |
| 493 | exportcppbutton:action(exportcpp) | |
| 494 | exportwindow:addComponent(exportcppbutton) | |
| 495 | ||
| 496 | exportwindow:onTryExit(function() | |
| 497 | ui.closeWindow(exportwindow) | |
| 498 | end) | |
| 499 | ||
| 500 | local function keypressed(key, keynum, mod, evt) | |
| 501 | if evt == 2 and key == "n" then | |
| 502 | ui.showWindow(window) | |
| 503 | end | |
| 504 | end | |
| 505 | ||
| 506 | loadelement(loadtext) | |
| 507 | ||
| 508 | tpt.register_keypress(keypressed) |