Differences From
Artifact [de8d4eba0f]:
1 1 local lib = starlit.mod.lib
2 2
3 3
4 -do -- chemlamp
5 - local burnTime = 60*60
6 - local maxBright = 12
7 - local stages = maxBright
4 +local function mkBurnDown(def) -- chemlamp
5 + local burnTime = def.time
6 + local stages = def.stages or 10
8 7 local stageTimeout = burnTime / stages
9 - local function chemLampID(n)
10 - if n == stages then return 'starlit_tech:chem_lamp' end
11 - return string.format('starlit_tech:chem_lamp_%s',n)
8 + local function stID(n)
9 + if n == stages then return def.id end
10 + return string.format('%s_%s',def.id,n)
12 11 end
13 - local fab = starlit.type.fab {
14 - element = { carbon = 4, magnesium = 1 };
15 - cost = { power = 100 };
16 - flag = { print = true };
17 - time = { print = 5 };
18 - };
12 + local fab = def.fab
19 13 for i = stages, 0, -1 do
20 - minetest.register_node(chemLampID(i), {
21 - short_description = 'Chem Lamp';
14 + local grp = {
15 + object = 1;
16 + attached_node = 1;
17 + }
18 + if def.group then
19 + for k,v in pairs(def.group((i/stages))) do grp[k]=v end
20 + end
21 + minetest.register_node(stID(i), {
22 + short_description = def.name;
22 23 description = starlit.ui.tooltip {
23 - title = 'Chem Lamp';
24 - desc = "A simple carbon-frame chemical light source powered by ambient oxygen. Cheap, quick to print, and biodedragable, without any need for an electric grid or complex power storage mechanism. However, the light only lasts a few days, after which the lamp must be recycled or discarded.";
25 - color = lib.color(1,.4,.1);
24 + title = def.name;
25 + desc = def.desc;
26 + color = def.color;
26 27 props = {
27 - {title = 'Burn Remaining', desc=lib.math.timespec(stageTimeout * i), affinity=i > 4 and 'good' or 'bad'};
28 - {title = 'Mass', desc='10g', affinity='info'};
28 + {title = 'Burn Remaining', desc=lib.math.timespec(stageTimeout * i), affinity=i > (stages/2) and 'good' or 'bad'};
29 + {title = 'Mass', desc=lib.math.siUI('g', def.mass), affinity='info'};
29 30 };
30 31 };
31 32 drawtype = 'nodebox';
32 - groups = {
33 - object = 1;
34 - attached_node = 1;
35 - };
33 + groups = grp;
36 34 node_box = {
37 35 type = 'fixed';
38 36 fixed = {
39 - -.4, -.5, -.20;
40 - .4, -.3, .20;
37 + -(7/16), -.5, -(4/16);
38 + (7/16), -.5 + (2/16), (4/16);
41 39 };
42 40 };
43 - tiles = {
44 - lib.image 'starlit-tech-lamp-glow.png'
45 - :fade(1 - i/stages)
46 - :blit(lib.image 'starlit-tech-lamp.png')
47 - :render();
48 - };
41 + tiles = def.tile((i/stages));
49 42 paramtype = 'light';
50 43 paramtype2 = 'wallmounted';
51 44 wallmounted_rotate_vertical = true;
52 - light_source = math.floor(lib.math.lerp(i/stages, 0, maxBright));
45 + light_source = math.floor(lib.math.lerp(i/stages, 0, def.glow));
53 46 on_construct = i ~= 0 and function(pos)
54 47 local t = minetest.get_node_timer(pos)
55 48 t:start(stageTimeout)
49 + if def.ctor then def.ctor(pos, (i/stages)) end
50 + end or nil;
51 + on_destruct = def.dtor and function(pos)
52 + def.dtor(pos, (i/stages))
56 53 end or nil;
57 54 on_timer = i ~= 0 and function(pos)
58 55 local me = minetest.get_node(pos)
59 - minetest.swap_node(pos, {name=chemLampID(i-1), param2=me.param2})
56 + minetest.swap_node(pos, {name=stID(i-1), param2=me.param2})
60 57 return i > 1
61 58 end or nil;
62 - _starlit = {
63 - mass = 10;
64 - reverseEngineer = {
65 - complexity = 1;
66 - sw = 'starlit_tech:schematic_chem_lamp';
67 - };
68 - recover = starlit.type.fab {
69 - element = {
70 - carbon = 8;
71 - magnesium = math.floor(lib.math.lerp(i/stages, 0, 2));
59 + _starlit = (function()
60 + local meta = {
61 + mass = def.mass;
62 + reverseEngineer = {
63 + complexity = 1;
64 + sw = def.id .. '_schematic';
65 + };
66 + recover = def.mat
67 + + (def.fuel / (i/stages))
68 + + starlit.type.fab {
69 + time = {
70 + shred = .5;
71 + shredPower = 2;
72 + };
72 73 };
73 - time = {
74 - shred = .5;
75 - shredPower = 2;
76 - };
77 - };
78 -
79 - };
74 + }
75 + for k,v in pairs(def.meta and def.meta((i/stages)) or {}) do meta[k]=v end
76 + return meta
77 + end)();
80 78 })
81 79 end
82 - starlit.item.sw.link('starlit_tech:schematic_chem_lamp', {
83 - name = 'Chem Lamp Schematic';
80 + starlit.item.sw.link(def.id .. '_schematic', {
81 + name = def.name .. ' Schematic';
84 82 kind = 'schematic';
85 - input = fab;
86 - output = chemLampID(stages);
83 + input = def.fab + def.mat + def.fuel;
84 + output = stID(stages);
87 85 size = 32e6;
88 86 cost = {
89 87 cycles = 8e9;
90 88 ram = 16e6;
91 89 };
92 90 rarity = 1;
93 91 })
94 92 end
95 93
94 +
95 +mkBurnDown {
96 + id = 'starlit_tech:chem_lamp';
97 + name = 'Chem Lamp';
98 + desc = "A simple carbon-frame chemical light source powered by ambient oxygen. Cheap, quick to print, and biodedragable, without any need for an electric grid or complex power storage mechanism. However, the light only lasts a few days, after which the lamp must be recycled or discarded.";
99 + stages = 12;
100 + glow = 12;
101 + time = 60*60;
102 + mass = 10;
103 + color = lib.color(1,.4,.1);
104 + tile = function(f) return {
105 + lib.image 'starlit-tech-lamp-glow.png'
106 + :fade(f)
107 + :blit(lib.image 'starlit-tech-lamp.png')
108 + :render();
109 + } end;
110 + fab = starlit.type.fab {
111 + cost = { power = 100 };
112 + flag = { print = true };
113 + time = { print = 5 };
114 + };
115 + mat = starlit.type.fab { element = { carbon = 4 }; };
116 + fuel = starlit.type.fab { element = { magnesium = 1 }; };
117 +}
118 +
119 +mkBurnDown {
120 + id = 'starlit_tech:chem_radiator';
121 + name = 'Chem Radiator';
122 + desc = "A simple carbon-frame chemical heat source powered by ambient oxygen. Cheap, quick to print, and biodedragable, without any need for an electric grid or complex power storage mechanism. However, the heat only lasts a few hours, after which the lamp must be recycled or discarded.";
123 + stages = 12;
124 + glow = 7;
125 + time = 15*60;
126 + mass = 10;
127 + color = lib.color(1,.4,.1);
128 + tile = function(f) return {
129 + lib.image 'starlit-tech-lamp-glow.png'
130 + :fade(f)
131 + :blit(lib.image 'starlit-tech-lamp.png')
132 + :tint{hue=0,sat=1,lum=.5}:render();
133 + } end;
134 + fab = starlit.type.fab {
135 + cost = { power = 150 };
136 + flag = { print = true };
137 + time = { print = 10 };
138 + };
139 + mat = starlit.type.fab { element = { carbon = 4 }; };
140 + fuel = starlit.type.fab { element = { magnesium = 2, iron = 2 }; };
141 + group = function(f)
142 + if f > 0
143 + then return {radiator=1}
144 + else return {}
145 + end
146 + end;
147 + ctor = function(pos, f) starlit.region.radiator.scan(pos) end;
148 + dtor = function(pos, f) starlit.region.radiator.unload(pos) end;
149 + meta = function(f) return {
150 + radiator = {
151 + radius = function(pos)
152 + return 2;
153 + end;
154 + radiate = function(rp, pos)
155 + return 15 * f
156 + end;
157 + };
158 + } end;
159 +}
96 160
97 161 minetest.register_node('starlit_tech:crate', {
98 162 short_description = 'Crate';
99 163 description = starlit.ui.tooltip {
100 164 title = 'Crate';
101 165 desc = 'A sturdy but lightweight storage crate woven from graphene.';
102 166 props = { {title='Mass', affinity='info', desc='100g'} };