starlit  Diff

Differences From Artifact [e6ca28c621]:

To Artifact [4c0283cfa3]:


171
172
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
246
247
248
249
250
251
252



























253
			};
		};
	});


end)

local function canisterMeta(stack)
	return lib.marshal.metaStore {
		contents = {key = 'starlit:canister_contents', type = starlit.store.volume};
	} (stack)
end


local function canisterDesc(stack, def)
	def = def or stack:get_definition()._starlit.canister
	local props = {
		{title = 'Volume', affinity = 'info', desc = lib.math.si('L', def.vol,nil,nil,2)};
	};
	if stack then
................................................................................
				desc = lib.math.si('g', e:get_count());
				affinity = 'good';
			})
		end ]]
		local itemMeta = canisterMeta(stack)
		local e = itemMeta.read 'contents'
		local mass = lib.math.si('g', e.mass, nil, nil, 2)
		local def, meas
		if e.kind == 'liquid' then
			def = M.liquid.db[e.id]
			local vol =  lib.math.si('L', e.mass * def.composition.density, nil, nil, 2)
			meas = string.format("%s %s (%s %s)", vol, def.name, e.mass, def.composition:formula())
		elseif e.kind == 'gas' then
			def = M.gas.db[e.id]
			meas = string.format("%s %s (%s)", mass, def.name, def.composition:formula())
		end
		local comp = def.composition
		table.insert(props, {
			title = meas;
			desc = def.desc;
			affinity = 'info';
		})
	end
	return starlit.ui.tooltip {
		title = def.name, desc = def.desc or 'A canister that can store a charge of gas or liquid';
		color = lib.color(0.2,0.1,0.1);
		props = props;
................................................................................
					};
				};
			};
		};
	})
end)




























starlit.item.canister.meta = canisterMeta







<
|
|
<
<
>







 







|

|
|
|

|
|




|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
171
172
173
174
175
176
177

178
179


180
181
182
183
184
185
186
187
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
			};
		};
	});


end)


local canisterMeta = lib.marshal.metaStore {
	contents = {key = 'starlit:canister_contents', type = starlit.store.volume};


}

local function canisterDesc(stack, def)
	def = def or stack:get_definition()._starlit.canister
	local props = {
		{title = 'Volume', affinity = 'info', desc = lib.math.si('L', def.vol,nil,nil,2)};
	};
	if stack then
................................................................................
				desc = lib.math.si('g', e:get_count());
				affinity = 'good';
			})
		end ]]
		local itemMeta = canisterMeta(stack)
		local e = itemMeta.read 'contents'
		local mass = lib.math.si('g', e.mass, nil, nil, 2)
		local mdef, meas
		if e.kind == 'liquid' then
			mdef = M.liquid.db[e.id]
			local vol =  lib.math.si('L', e.mass * mdef.density, nil, nil, 2)
			meas = string.format("%s %s (%s %s)", vol, mdef.name, e.mass, mdef.composition:formula())
		elseif e.kind == 'gas' then
			mdef = M.gas.db[e.id]
			meas = string.format("%s %s (%s)", mass, mdef.name, mdef.composition:formula())
		end
		local comp = def.composition
		table.insert(props, {
			title = meas;
			desc = mdef.desc;
			affinity = 'info';
		})
	end
	return starlit.ui.tooltip {
		title = def.name, desc = def.desc or 'A canister that can store a charge of gas or liquid';
		color = lib.color(0.2,0.1,0.1);
		props = props;
................................................................................
					};
				};
			};
		};
	})
end)

function starlit.item.canister.contents(st)
	local m = canisterMeta(st)
	return m.read 'contents'
end

function starlit.item.canister.update(st)
	st:get_meta():set_string('description', canisterDesc(st))
end

function starlit.item.canister.replace(st, rec)
	local m = canisterMeta(st)
	m.write('contents', rec)
	starlit.item.canister.update(st)
end

function starlit.item.canister.empty(st, rec)
	local m = st:get_meta()
	m:set_string('starlit:canister_contents', '')
	m:set_string('description', '')
end

function starlit.item.canister.insert(st, rec)
	local m = canisterMeta(st)
	-- TODO
	starlit.item.canister.update(st)
end

-- starlit.item.canister.meta = canisterMeta