starlit  Diff

Differences From Artifact [e6ca28c621]:

To Artifact [4c0283cfa3]:


   171    171   			};
   172    172   		};
   173    173   	});
   174    174   
   175    175   
   176    176   end)
   177    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
          178  +local canisterMeta = lib.marshal.metaStore {
          179  +	contents = {key = 'starlit:canister_contents', type = starlit.store.volume};
          180  +}
   183    181   
   184    182   local function canisterDesc(stack, def)
   185    183   	def = def or stack:get_definition()._starlit.canister
   186    184   	local props = {
   187    185   		{title = 'Volume', affinity = 'info', desc = lib.math.si('L', def.vol,nil,nil,2)};
   188    186   	};
   189    187   	if stack then
................................................................................
   196    194   				desc = lib.math.si('g', e:get_count());
   197    195   				affinity = 'good';
   198    196   			})
   199    197   		end ]]
   200    198   		local itemMeta = canisterMeta(stack)
   201    199   		local e = itemMeta.read 'contents'
   202    200   		local mass = lib.math.si('g', e.mass, nil, nil, 2)
   203         -		local def, meas
          201  +		local mdef, meas
   204    202   		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())
          203  +			mdef = M.liquid.db[e.id]
          204  +			local vol =  lib.math.si('L', e.mass * mdef.density, nil, nil, 2)
          205  +			meas = string.format("%s %s (%s %s)", vol, mdef.name, e.mass, mdef.composition:formula())
   208    206   		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())
          207  +			mdef = M.gas.db[e.id]
          208  +			meas = string.format("%s %s (%s)", mass, mdef.name, mdef.composition:formula())
   211    209   		end
   212    210   		local comp = def.composition
   213    211   		table.insert(props, {
   214    212   			title = meas;
   215         -			desc = def.desc;
          213  +			desc = mdef.desc;
   216    214   			affinity = 'info';
   217    215   		})
   218    216   	end
   219    217   	return starlit.ui.tooltip {
   220    218   		title = def.name, desc = def.desc or 'A canister that can store a charge of gas or liquid';
   221    219   		color = lib.color(0.2,0.1,0.1);
   222    220   		props = props;
................................................................................
   246    244   					};
   247    245   				};
   248    246   			};
   249    247   		};
   250    248   	})
   251    249   end)
   252    250   
   253         -starlit.item.canister.meta = canisterMeta
          251  +function starlit.item.canister.contents(st)
          252  +	local m = canisterMeta(st)
          253  +	return m.read 'contents'
          254  +end
          255  +
          256  +function starlit.item.canister.update(st)
          257  +	st:get_meta():set_string('description', canisterDesc(st))
          258  +end
          259  +
          260  +function starlit.item.canister.replace(st, rec)
          261  +	local m = canisterMeta(st)
          262  +	m.write('contents', rec)
          263  +	starlit.item.canister.update(st)
          264  +end
          265  +
          266  +function starlit.item.canister.empty(st, rec)
          267  +	local m = st:get_meta()
          268  +	m:set_string('starlit:canister_contents', '')
          269  +	m:set_string('description', '')
          270  +end
          271  +
          272  +function starlit.item.canister.insert(st, rec)
          273  +	local m = canisterMeta(st)
          274  +	-- TODO
          275  +	starlit.item.canister.update(st)
          276  +end
          277  +
          278  +-- starlit.item.canister.meta = canisterMeta