Differences From
Artifact [277b90dbc5]:
1 1 -- [ʞ] starlit/init.lua
2 2 -- ~ lexi hale <lexi@hale.su>
3 3 -- ? basic setup, game rules, terrain
4 4 -- © EUPL v1.2
5 5
6 -local T = minetest.get_translator 'starlit'
6 +local T = core.get_translator 'starlit'
7 7
8 8 -- TODO enforce latest engine version
9 9
10 10 local mod = {
11 11 -- subordinate mods register here
12 12 lib = vtlib;
13 13 -- vtlib should be accessed as starlit.mod.lib by starlit modules for the sake of proper encapsulation. vtlib should simply be a provider, not a hardcoded dependency
14 14 }
15 15 local lib = mod.lib
16 16
17 17
18 18 starlit = {
19 - ident = minetest.get_current_modname();
19 + ident = core.get_current_modname();
20 20 mod = mod;
21 21 translator = T;
22 22
23 23 constant = {
24 - light = { --minetest units
24 + light = { --luanti units
25 25 dim = 3;
26 26 lamp = 7;
27 27 bright = 10;
28 28 brightest = 14; -- only sun and growlights
29 29 };
30 30 heat = { -- celsius
31 31 freezing = 0;
................................................................................
35 35 thermalConductivity = 0.05; -- κ
36 36 };
37 37 rad = {
38 38 };
39 39
40 40 phys = {
41 41 --- HACK HACK HAAAAAAAAAAACK
42 - engineGravity = minetest.settings:get('movement_gravity') or 9.81
42 + engineGravity = core.settings:get('movement_gravity') or 9.81
43 43 };
44 44 };
45 45
46 46 activeUsers = {
47 47 -- map of username -> user object
48 48 };
49 49 activeUI = {
................................................................................
71 71
72 72 -- standardized effects
73 73 fx = {};
74 74
75 75 type = {};
76 76 world = {
77 77 defaultScenario = 'starlit_scenario:imperialExpat';
78 - seedbank = lib.math.seedbank(minetest.get_mapgen_setting 'seed');
78 + seedbank = lib.math.seedbank(core.get_mapgen_setting 'seed');
79 79 mineral = lib.registry.mk 'starlit:mineral';
80 80 material = { -- raw materials
81 81 element = lib.registry.mk 'starlit:element';
82 82 -- elements are automatically sorted into the following categories
83 83 -- if they match. however, it's possible to have a metal/gas/liquid
84 84 -- that *isn't* a pure element, so these need separate registries
85 85 -- for alloys and mixtures like steel and water
................................................................................
177 177 };
178 178
179 179 jobs = {};
180 180 }
181 181
182 182 -- TODO deal with core.DEFAULT_PHYSICS once it hits master
183 183
184 -starlit.cfgDir = minetest.get_worldpath() .. '/' .. starlit.ident
184 +starlit.cfgDir = core.get_worldpath() .. '/' .. starlit.ident
185 185
186 186 local logger = function(module)
187 187 local function argjoin(arg, nxt, ...)
188 188 if arg and not nxt then return tostring(arg) end
189 189 if not arg then return "(nil)" end
190 190 return tostring(arg) .. ' ' .. argjoin(nxt, ...)
191 191 end
192 192 local lg = {}
193 193 local setup = function(fn, lvl)
194 194 lvl = lvl or fn
195 195 local function emit(...)
196 196 local call = (fn == 'fatal') and error
197 - or function(str) minetest.log(lvl, str) end
197 + or function(str) core.log(lvl, str) end
198 198 if module
199 199 then call(string.format('[%s :: %s] %s',starlit.ident,module,argjoin(...)))
200 200 else call(string.format('[%s] %s',starlit.ident,argjoin(...)))
201 201 end
202 202 end
203 203 lg[fn ] = function(...) emit(...) end
204 204 lg[fn .. 'f'] = function(...) emit(string.format(...)) end -- convenience fn
................................................................................
212 212 end
213 213
214 214 starlit.logger = logger
215 215
216 216 local log = logger()
217 217
218 218 function starlit.evaluate(name, ...)
219 - local path = minetest.get_modpath(minetest.get_current_modname())
219 + local path = core.get_modpath(core.get_current_modname())
220 220 local filename = string.format('%s/%s', path, name)
221 221 log.info('loading', filename)
222 222 local chunk, err = loadfile(filename, filename)
223 223 if not chunk then error(err) end
224 224 return chunk(...)
225 225 end
226 226
227 227 function starlit.include(name, ...) -- semantic variant used for loading modules
228 228 return starlit.evaluate(name..'.lua', ...)
229 229 end
230 230
231 231 function starlit.region.radiator.scan(pos,node)
232 232 local R = starlit.region
233 - local phash = minetest.hash_node_position(pos)
233 + local phash = core.hash_node_position(pos)
234 234 if R.radiator.sources[phash] then return end -- already loaded
235 - node = node or minetest.get_node(pos)
235 + node = node or core.get_node(pos)
236 236
237 - local def = minetest.registered_nodes[node.name]
237 + local def = core.registered_nodes[node.name]
238 238 local cl = def._starlit and def._starlit.radiator
239 239 if not cl then return nil end
240 240 local min,max = cl.maxEffectArea and cl.maxEffectArea(pos) or nil
241 241 if not min then
242 242 assert(cl.radius, 'no radius callback for radiator')
243 243 local r = cl.radius(pos)
244 244 local vr = vector.new(r,r,r)
245 245 min,max = pos-vr, pos+vr
246 246 end
247 - local id = R.radiator.store:insert_area(min,max, minetest.pos_to_string(pos))
247 + local id = R.radiator.store:insert_area(min,max, core.pos_to_string(pos))
248 248 R.radiator.sources[phash] = id
249 249 end
250 250
251 251 function starlit.region.radiator.unload(pos)
252 252 local R = starlit.region
253 - local phash = minetest.hash_node_position(pos)
253 + local phash = core.hash_node_position(pos)
254 254 local id = R.radiator.sources[phash]
255 255 R.radiator.store:remove_area(id)
256 256 R.radiator.sources[phash] = nil
257 257 end
258 258
259 -minetest.register_lbm {
259 +core.register_lbm {
260 260 label = 'build radiator index';
261 261 name = 'starlit:loadradiatorboxes';
262 262 nodenames = {'group:radiator'};
263 263 run_at_every_load = true;
264 264 action = function(pos, node, dt)
265 265 starlit.region.radiator.scan(pos, node)
266 266 end;
................................................................................
267 267 -- NOTE: temp emitter nodes are responsible for decaching themselves in their on_destruct cb
268 268 }
269 269
270 270
271 271 function starlit.startJob(id, interval, job)
272 272 local lastRun
273 273 local function start()
274 - starlit.jobs[id] = minetest.after(interval, function()
275 - local t = minetest.get_gametime()
274 + starlit.jobs[id] = core.after(interval, function()
275 + local t = core.get_gametime()
276 276 local d = lastRun and t - lastRun or nil
277 277 lastRun = t
278 278 local continue = job(d, interval)
279 279 if continue == true or continue == nil then
280 280 start()
281 281 elseif continue ~= false then
282 282 interval = continue
................................................................................
307 307 starlit.include 'element'
308 308
309 309 starlit.include 'terrain'
310 310 starlit.include 'interfaces'
311 311 starlit.include 'compile'
312 312 starlit.include 'suit'
313 313
314 --- minetest.settings:set('movement_gravity', starlit.world.planet.gravity) -- ??? seriously???
314 +-- core.settings:set('movement_gravity', starlit.world.planet.gravity) -- ??? seriously???
315 315 -- THIS OVERRIDES THE GLOBAL SETTING *AND PERSISTS IT* WHAT IN THE SATANIC FUCK
316 316
317 317 ---------------
318 318 -- callbacks --
319 319 ---------------
320 --- here we connect our types up to the minetest API
320 +-- here we connect our types up to the luanti API
321 321
322 322 local function userCB(fn)
323 323 return function(luser, ...)
324 324 local name = luser:get_player_name()
325 325 local user = starlit.activeUsers[name]
326 326 return fn(user, ...)
327 327 end
328 328 end
329 329
330 -minetest.register_on_joinplayer(function(luser, lastLogin)
330 +core.register_on_joinplayer(function(luser, lastLogin)
331 331 -- TODO check that necessary CSMs are installed
332 332 local user = starlit.type.user(luser)
333 333
334 334 if lastLogin == nil then
335 335 user:onSignup()
336 336 end
337 337 user:onJoin()
338 338
339 339 starlit.activeUsers[user.name] = user
340 340 end)
341 341
342 -minetest.register_on_leaveplayer(function(luser)
342 +core.register_on_leaveplayer(function(luser)
343 343 starlit.activeUsers[luser:get_player_name()]:onPart()
344 344 end)
345 345
346 -minetest.register_on_player_receive_fields(function(luser, formid, fields)
346 +core.register_on_player_receive_fields(function(luser, formid, fields)
347 347 local name = luser:get_player_name()
348 348 local user = starlit.activeUsers[name]
349 349 if not user then return false end
350 350 if formid == '' then -- main menu
351 351 return starlit.ui.userMenuDispatch(user,fields)
352 352 end
353 353 local ui = starlit.interface.db[formid]
................................................................................
362 362 user:onRespond(ui, state, fields)
363 363 if fields.quit then
364 364 starlit.activeUI[name] = nil
365 365 end
366 366 return true
367 367 end)
368 368
369 -minetest.register_on_respawnplayer(userCB(function(user)
369 +core.register_on_respawnplayer(userCB(function(user)
370 370 return user:onRespawn()
371 371 end))
372 372
373 -minetest.register_on_dieplayer(userCB(function(user, reason)
373 +core.register_on_dieplayer(userCB(function(user, reason)
374 374 return user:onDie(reason)
375 375 end))
376 376
377 -minetest.register_on_punchnode(function(pos,node,puncher,point)
377 +core.register_on_punchnode(function(pos,node,puncher,point)
378 378 local user = starlit.activeUsers[puncher:get_player_name()]
379 379 local oldTgt = user.action.tgt
380 380 user.action.tgt = point
381 381 if bit.band(user.action.bits, 0x80)==0 then
382 382 user.action.bits = bit.bor(user.action.bits, 0x80)
383 383 --user:trigger('primary', {state = 'init'})
384 384 else
................................................................................
403 403 user:trigger('retarget', {oldTgt = oldTgt})
404 404 end
405 405 end
406 406 -- sigh
407 407 --[[
408 408 core.noneitemdef_default.on_place = function(...)
409 409 if not triggerPower(...) then
410 - minetest.item_place(...)
410 + core.item_place(...)
411 411 end
412 412 end
413 413 core.noneitemdef_default.on_use = function(...) triggerPower(...) end
414 414 core.noneitemdef_default.on_secondary_use = function(...) triggerPower(...) end
415 415 ]]
416 -minetest.register_item(":", {
416 +core.register_item(":", {
417 417 type = "none",
418 418 wield_image = "wieldhand.png",
419 419 wield_scale = {x=1,y=1,z=2.5},
420 420 on_secondary_use = function(...) triggerPower(...) end;
421 421 -- on_use = function(...) print'base' end;
422 422 after_use = function(i,u,n,p)
423 423 if (u:is_player()) then triggerPower(i,u,p) end
424 424 end;
425 425 })
426 -minetest.register_item("starlit:_hand_dig", {
426 +core.register_item("starlit:_hand_dig", {
427 427 type = "none",
428 428 wield_image = "wieldhand.png",
429 429 wield_scale = {x=1,y=1,z=2.5},
430 430 tool_capabilities = {
431 431 groupcaps = {
432 432 object = {maxlevel=1, times = {.10,.20,.40}};
433 433 plant = {maxlevel=1, times = {.50}};
................................................................................
434 434
435 435 -- sand, dirt, gravel
436 436 looseClump = {maxlevel=1, times = {1.5, 2.5}};
437 437 };
438 438 }
439 439 })
440 440
441 -minetest.register_on_player_inventory_action(function(luser, act, inv, p)
441 +core.register_on_player_inventory_action(function(luser, act, inv, p)
442 442 local name = luser:get_player_name()
443 443 local user = starlit.activeUsers[name]
444 444 -- allow UIs to update on UI changes
445 445 local state = starlit.activeUI[name]
446 446 if state then
447 447 local ui = starlit.interface.db[state.form]
448 448 ui:cb('onMoveItem', user, act, inv, p)
449 449 end
450 450 end)
451 451
452 -minetest.register_on_player_hpchange(function(luser, delta, cause)
452 +core.register_on_player_hpchange(function(luser, delta, cause)
453 453 local user = starlit.activeUsers[luser:get_player_name()]
454 454 if cause.type == 'fall' then
455 455 delta = user:damageModifier('bluntForceTrauma', (delta * 50))
456 456 -- justification: a short fall can do around
457 457 -- five points of damage, which is nearly 50%
458 458 -- of the default hp_max. since we crank up
459 459 -- hp by a factor of 50~40, damage should be
460 460 -- cranked by similarly
461 461 end
462 462 return delta
463 463 end, true)
464 464
465 -function minetest.handle_node_drops(pos, drops, digger)
465 +function core.handle_node_drops(pos, drops, digger)
466 466 local function jitter(pos)
467 467 local function r(x) return x+math.random(-0.01, 0.01) end
468 468 return vector.new(
469 469 r(pos.x),
470 470 r(pos.y),
471 471 r(pos.z)
472 472 )
473 473 end
474 474 for i, it in ipairs(drops) do
475 475 if type(it) == 'string' then it = ItemStack(it) end
476 476 if not it:is_empty() then
477 - local ent = minetest.add_item(jitter(pos), it)
477 + local ent = core.add_item(jitter(pos), it)
478 478 if ent ~= nil then -- avoid crash when dropping unknown item
479 479 local dp = vector.new(0,0,0)
480 480 if digger then dp = digger:get_pos() end
481 481 local delta = dp - ent:get_pos()
482 482 ent:add_velocity(vector.new(delta.x,0,delta.z));
483 483 end
484 484 end
485 485 end
486 486 end
487 487
488 488
489 489 -- TODO timer iterates live UI
490 490