Differences From
Artifact [db8d1e2ad1]:
12 12 -- for the object in question; e.g a normal chunk will be
13 13 -- 100 $element, an ingot will be 1000 $element
14 14 })
15 15 elseif m.gas then
16 16 M.gas.link(id, {
17 17 name = m.name;
18 18 composition = starlit.type.fab{element = {[id] = 1}};
19 + density = m.density;
19 20 })
20 21 elseif m.liquid then
21 22 M.liquid.link(id, {
22 23 name = m.name;
23 24 composition = starlit.type.fab{element = {[id] = 1}};
25 + density = m.density;
24 26 })
25 27 end
26 28 end)
27 29
28 30 local F = string.format
29 31
30 32 local function mkEltIndicator(composition)
................................................................................
63 65 props = {
64 66 {title = 'Mass', desc = lib.math.si('g', g), affinity='info'}
65 67 }
66 68 }
67 69 end
68 70 local comp = {[id] = 1}
69 71 local iblit = mkEltIndicator(comp)
72 + local function img(s)
73 + return iblit(s:colorize(m.color):render())
74 + end
75 +
70 76 m.form = m.form or {}
71 - m.form.element = eltID
72 77
73 - local powder = F('starlit-element-%s-powder.png', id);
78 +
79 + if not (m.gas or m.liquid) then
80 + local brickID = eltID .. '_brick'
81 + local brickName = F('%s Brick', lib.str.capitalize(m.name))
82 + m.form.brick = brickID
83 + minetest.register_craftitem(brickID, {
84 + short_description = brickName;
85 + description = tt(brickName, F('A small brick of %s, ready to be worked by a matter compiler', m.name), 1);
86 + inventory_image = img(lib.image 'starlit-item-brick.png');
87 + wield_image = lib.image 'starlit-item-brick.png':colorize(m.color):render();
88 + stack_max = 500;
89 + groups = {element=1, brick=1};
90 + _starlit = {
91 + mass = 1;
92 + material = {
93 + kind = 'element';
94 + element = id;
95 + };
96 + fab = starlit.type.fab {
97 + element = comp;
98 + };
99 + };
100 + });
101 + end
102 +
103 + --[[
104 + local chunk = F('starlit-element-%s-powder.png', id);
74 105 minetest.register_craftitem(eltID, {
75 106 short_description = eltName;
76 - description = tt(eltName, F('Elemental %s kept in suspension by a nanide storage system, ready to be worked by a cold matter compiler', m.name), 1);
77 - inventory_image = iblit(powder);
107 + description = tt(eltName, F('A 1g chunk of elemental %s, ready to be worked by a cold matter compiler', m.name), 1);
108 + inventory_image = iblit(chunk);
78 109 wield_image = powder;
79 110 stack_max = 1000; -- 1kg
80 - groups = {element = 1, powder = 1, specialInventory = 1};
111 + groups = {element = 1, chunk = 1};
81 112 _starlit = {
82 113 mass = 1;
83 114 material = {
84 115 kind = 'element';
85 116 element = id;
86 117 };
87 118 fab = starlit.type.fab {
88 119 element = comp;
89 120 };
90 121 };
91 122 });
123 + ]]
92 124 end)
93 125
94 126
95 127 M.metal.foreach('starlit:gen-forms', {}, function(id, m)
96 128 local baseID = F('%s:metal_%s_', minetest.get_current_modname(), id)
97 - local brickID, ingotID = baseID .. 'brick', baseID .. 'ingot'
98 - local brickName, ingotName =
99 - F('%s Brick', lib.str.capitalize(m.name)),
100 - F('%s Ingot', lib.str.capitalize(m.name))
129 + local ingotID = baseID .. 'ingot'
130 + local ingotName = F('%s Ingot', lib.str.capitalize(m.name))
101 131 m.form = m.form or {}
102 - m.form.brick = brickID
103 132 m.form.ingot = ingotID
104 133 local tt = function(t, d, g)
105 134 return starlit.ui.tooltip {
106 135 title = t, desc = d;
107 136 color = lib.color(0.1,0.1,0.1);
108 137 props = {
109 138 {title = 'Mass', desc = lib.math.si('g', g), affinity='info'}
................................................................................
119 148 return t
120 149 end
121 150 local iblit = mkEltIndicator(mcomp)
122 151 local function img(s)
123 152 return iblit(s:colorize(m.color):render())
124 153 end
125 154
126 - minetest.register_craftitem(brickID, {
127 - short_description = brickName;
128 - description = tt(brickName, F('A solid brick of %s, ready to be worked by a matter compiler', m.name), 100);
129 - inventory_image = img(lib.image 'starlit-item-brick.png');
130 - wield_image = lib.image 'starlit-item-brick.png':colorize(m.color):render();
131 - stack_max = 10;
132 - groups = {metal = 1, ingot = 1};
133 - _starlit = {
134 - mass = 100;
135 - material = {
136 - kind = 'metal';
137 - metal = id;
138 - };
139 - fab = starlit.type.fab {
140 - flag = {smelt= true};
141 - element = comp(1e2);
142 - };
143 - };
144 - });
145 -
146 155 minetest.register_craftitem(ingotID, {
147 156 short_description = ingotName;
148 157 description = tt(ingotName, F('A solid ingot of %s, ready to be worked by a large matter compiler', m.name), 1e3);
149 158 inventory_image = img(lib.image('starlit-item-ingot.png'));
150 159 wield_image = lib.image 'starlit-item-ingot.png':colorize(m.color):render();
151 160 groups = {metal = 1, ingot = 1};
152 161 stack_max = 5;
................................................................................
161 170 element = comp(1e3);
162 171 };
163 172 };
164 173 });
165 174
166 175
167 176 end)
177 +
178 +local function canisterMeta(stack)
179 + return lib.marshal.metaStore {
180 + contents = {key = 'starlit:canister_contents', type = starlit.store.volume};
181 + } (stack)
182 +end
168 183
169 184 local function canisterDesc(stack, def)
170 185 def = def or stack:get_definition()._starlit.canister
171 186 local props = {
172 - {title = 'Charge Slots', affinity = 'info', desc = tostring(def.slots)};
187 + {title = 'Volume', affinity = 'info', desc = lib.math.si('L', def.vol,nil,nil,2)};
173 188 };
174 189 if stack then
190 + --[[
175 191 local inv = starlit.item.container(stack)
176 192 for i,e in ipairs(inv:list 'elem') do
177 193 local comp = e:get_definition()._starlit.fab
178 194 table.insert(props, {
179 195 title = comp:formula();
180 196 desc = lib.math.si('g', e:get_count());
181 197 affinity = 'good';
182 198 })
199 + end ]]
200 + local itemMeta = canisterMeta(stack)
201 + local e = itemMeta.read 'contents'
202 + local mass = lib.math.si('g', e.mass, nil, nil, 2)
203 + local def, meas
204 + if e.kind == 'liquid' then
205 + def = M.liquid.db[e.id]
206 + local vol = lib.math.si('L', e.mass * def.composition.density, nil, nil, 2)
207 + meas = string.format("%s %s (%s %s)", vol, def.name, e.mass, def.composition:formula())
208 + elseif e.kind == 'gas' then
209 + def = M.gas.db[e.id]
210 + meas = string.format("%s %s (%s)", mass, def.name, def.composition:formula())
183 211 end
184 - -- TODO list masses
212 + local comp = def.composition
213 + table.insert(props, {
214 + title = meas;
215 + desc = def.desc;
216 + affinity = 'info';
217 + })
185 218 end
186 219 return starlit.ui.tooltip {
187 - title = def.name, desc = def.desc or 'A canister that can store a charge of elemental powder, gas, or liquid';
220 + title = def.name, desc = def.desc or 'A canister that can store a charge of gas or liquid';
188 221 color = lib.color(0.2,0.1,0.1);
189 222 props = props;
190 223 };
191 224 end
192 225
193 226 starlit.item.canister = lib.registry.mk 'starlit:canister';
194 227 starlit.item.canister.foreach('starlit:item-gen', {}, function(id, c)
................................................................................
212 245 sz = c.slots;
213 246 };
214 247 };
215 248 };
216 249 };
217 250 })
218 251 end)
252 +
253 +starlit.item.canister.meta = canisterMeta