starlit  Diff

Differences From Artifact [7b434e8bee]:

To Artifact [35031ce713]:


     5      5   B.path = {}
     6      6   -- this maps stage IDs to tables of the following form
     7      7   --[[ {
     8      8   	part = {
     9      9   		['starlit_building:pipe'] = 'myMod:stage3';
    10     10   	};
    11     11   	tool = {
    12         -		['starlit:scredriver'] = 'myMod:otherThing_stage1';
           12  +		['starlit:screwdriver'] = 'myMod:otherThing_stage1';
    13     13   		['starlit:saw'] = function(node, tool)
    14     14   			minetest.replace_node(node, {name='myMod:stage1'})
    15     15   			minetest.drop_item(node, 'starlit_building:pipe')
    16     16   		end;
    17     17   		['myMod:laserWrench'] = {
    18     18   			allow = function(node, tool) ... end;
    19     19   			handle = function(node, tool) ... end;
................................................................................
    59     59   			fixed = { ... };
    60     60   		};
    61     61   	})
    62     62   ]]
    63     63   
    64     64   B.part = lib.registry.mk 'starlit_building:part'
    65     65   -- a part is implemented as a special craftitem with the proper callbacks
    66         --- to index the registries and place/replace noes by reference to the
           66  +-- to index the registries and place/replace nodes by reference to the
    67     67   -- build tree.
    68     68   --[[
    69     69   	starlit.mod.building.part.link(id, {
    70     70   		name = ''; -- display name
    71     71   		desc = ''; -- display desc
    72     72   		img = ''; -- display image
           73  +		mass = 0;
           74  +		fab = {}; -- (optional) auto-gen schematic
           75  +		rarity = 0;
    73     76   	})
    74     77   ]]
           78  +B.part.foreach('starlit:partGen', {}, function(id, e)
           79  +	local props = {}
           80  +	if e.mass then
           81  +		table.insert(props, {title='Mass', desc=lib.math.siUI('g',e.mass), affinity='info'})
           82  +	end
           83  +	local rev, scmID
           84  +	if e.fab then
           85  +		scmID = string.format('%s_schematic', id)
           86  +		rev = {
           87  +			sw = scmID;
           88  +			complexity = e.complexity or 1;
           89  +		}
           90  +	end
           91  +	minetest.register_craftitem(id, {
           92  +		short_description = e.name;
           93  +		description = starlit.ui.tooltip {
           94  +			title = e.name;
           95  +			desc = e.desc;
           96  +			props = props;
           97  +		};
           98  +		inventory_image = e.img;
           99  +		_starlit = {
          100  +			mass = e.mass;
          101  +			reverseEngineer = rev;
          102  +			recover = e.recover or e.fab;
          103  +		};
          104  +	})
          105  +	if e.fab then
          106  +		starlit.item.sw.link(scmID, {
          107  +			kind = 'schematic';
          108  +			name = string.format('%s Schematic', e.name);
          109  +			size = e.size or 32e6;
          110  +			input = e.fab;
          111  +			output = id;
          112  +			cost = e.cost or {
          113  +				cycles = 4e9;
          114  +				ram = 1e9;
          115  +			};
          116  +			rarity = e.rarity or 0;
          117  +		})
          118  +	end
          119  +
          120  +end)
    75    121   
    76    122   B.stage.foreach('starlit:stageGen', {}, function(id, e)
    77    123   	local box = {type = 'fixed', fixed = {}}
    78    124   	local tex = {}
    79    125   	local ofs = vector.new(0,0,0)
    80    126   	for idx, p in ipairs(e.pieces) do
    81    127   		local ho, pieceID, pos
................................................................................
   129    175   end
   130    176   
   131    177   function B.pathFind(from, kind, what)
   132    178   	if not B.path[from] then return nil end
   133    179   	return B.path[from][kind][what]
   134    180   end
   135    181   
          182  +starlit.include 'parts'