starlit  Diff

Differences From Artifact [35031ce713]:

To Artifact [76e0104e11]:


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
92
93
94
95
96
97
98










































99
100
101
102
103
104
105
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181




































182

			allow = function(node, tool) ... end;
			handle = function(node, tool) ... end;
		};
	};
} ]]
-- it should only be written by special accessor functions!

B.stage = lib.registry.mk 'starlit_building:stage'
-- a stage consists of a list of pieces and maps from possible materials
-- / tool usages to succeeding stages in the build tree. note that all
-- used pieces must be defined before a stage is defined currently, due
-- to a lack of cross-registry dependency mechanisms. i will hopefully
-- improve vtlib to handle this condition eventually.
--[[
	starlit.mod.building.stage.link(id, {
		pieces = {
			'starlit_building:foundation';
			'starlit_building:insulation'; -- offset             ofsFac
			{'starlit_building:pipe',      vector.new(-.5, 0, 0), 0};--
			{'starlit_building:pipe',      vector.new(-.5, 0, 0), 1};
			'starlit_building:insulation';
			'starlit_building:panel';
		};
	})
]]

B.piece = lib.registry.mk 'starlit_building:piece'
-- a piece is used to produce stage definitions, by means of appending
-- nodeboxes with appropriate offsets. it also lists the recoverable
-- materials which can be obtained by destroying a stage containing
-- this piece using nano. part IDs should correspond with piece IDs
-- where possible
--[[
	starlit.mod.building.piece.link(id, {
		tex = 'myMod_part.png';
		height = 0.1; -- used for auto-offset
		fab = {
			element = {iron=10};
		};	
		shape = {
			type = "fixed";
			fixed = { ... };
		};
	})
]]

B.part = lib.registry.mk 'starlit_building:part'
-- a part is implemented as a special craftitem with the proper callbacks
-- to index the registries and place/replace nodes by reference to the
................................................................................
		short_description = e.name;
		description = starlit.ui.tooltip {
			title = e.name;
			desc = e.desc;
			props = props;
		};
		inventory_image = e.img;










































		_starlit = {
			mass = e.mass;
			reverseEngineer = rev;
			recover = e.recover or e.fab;
		};
	})
	if e.fab then
................................................................................
			};
			rarity = e.rarity or 0;
		})
	end

end)

B.stage.foreach('starlit:stageGen', {}, function(id, e)
	local box = {type = 'fixed', fixed = {}}
	local tex = {}
	local ofs = vector.new(0,0,0)
	for idx, p in ipairs(e.pieces) do
		local ho, pieceID, pos
		if type(p) == 'string' then
			pieceID, pos, ho = p, vector.zero(), 1.0
		else
			pieceID, pos, ho = pc[1],pc[2],pc[3]
		end
		local pc = B.piece.db[pieceID]
		pos = pos + ofs
		if ho ~= 0.0 then
			ofs = vector.offset(ofs, 0, pc.height)
		end
		local sh = lib.node.boxwarped(pc.shape, function(b)
			-- { -x, -y, -z;
			--   +x, +y, +z }
			b[1] = b[1] + ofs.x  b[4] = b[4] + ofs.x
			b[2] = b[2] + ofs.y  b[5] = b[5] + ofs.y
			b[3] = b[3] + ofs.z  b[6] = b[6] + ofs.z
		end)
		table.insert(box, sh)
		if type(pc.tex) == 'string' then
			table.insert(tex, pc.tex)
		else
			for i,t in ipairs(pc.tex) do
				table.insert(tex, t or '')
			end
		end
	end
	minetest.register_node(id, {
		description = 'Construction';
		drawtype = 'nodebox';
		paramtype  = 'light';
		paramtype2 = e.stateful or 'none';
		textures = tex;
		node_box = box;
		group = { stage = 1 };
		_starlit = {
			stage = id;
		};
	})
end)

function B.pathLink(from, kind, what, to)
	if not B.path[from] then
		B.path[from] = {part={}, tool={}}
	end
	local k = B.path[from][kind]
	assert(k[what] == nil)
	k[what] = to
end

function B.pathFind(from, kind, what)
	if not B.path[from] then return nil end
	return B.path[from][kind][what]
end





































starlit.include 'parts'








|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56



57
58
59
60
61
62
63
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
154
155
156
157
158
159
160














































161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
			allow = function(node, tool) ... end;
			handle = function(node, tool) ... end;
		};
	};
} ]]
-- it should only be written by special accessor functions!

B.begin = {part = {}, tool = {}}
-- this maps parts/tools to the new nodes they create
--[[
	part = {
		['starlit_building:concrete'] = 'starlit_building:stage_foundation';
		-- or function(...)
	};
	tool = {
		-- for consistency's sake -- can't quite imagine a valid use
		-- for this but im sure it'll bite me eventually if i leave it out
	};
]]

B.stage = lib.registry.mk 'starlit_building:stage'
-- a stage consists of a node definition and maps from possible materials
-- / tool usages to succeeding stages in the build tree
--[[
	starlit.mod.building.stage.link(id, {
		tex = { ... };
		box = { ... }; -- nodebox def, or
		mesh = '...'; -- mesh name
		begin = {
			part = {...};
			tool = {...};
		}
		build = {
			part = {
				['starlit_building:insulation'] = 'starlit_building:foundation_with_insulation';
			};
			tool = {
				['starlit_building:screwdriver'] = {id = 'air', drop = 'starlit_building:foundation'};
			};



		};
	})
]]

B.part = lib.registry.mk 'starlit_building:part'
-- a part is implemented as a special craftitem with the proper callbacks
-- to index the registries and place/replace nodes by reference to the
................................................................................
		short_description = e.name;
		description = starlit.ui.tooltip {
			title = e.name;
			desc = e.desc;
			props = props;
		};
		inventory_image = e.img;
		on_place = function(stack, luser, point)
			local node = minetest.get_node(point.under)
			local function tryBuild()
				local p = B.path[node.name]
				if not p then return nil end
				if (not p.part) or (not p.part[id]) then return nil end
				local n = p.part[id]
				local obj
				if type(n) == 'function' then
					obj = n(stack, node, point)
					if obj == nil then return nil end
				else
					obj = ItemStack(n)
					stack:take_item(1)
				end
				local pname = obj:get_name()
				local stg = B.stage.db[pname]
				node.name = pname
				minetest.swap_node(point.under, node)
				-- TODO make a noise
				if stg.onBuild then
					stg.onBuild(point.under, luser, stack)
				end
				return stack
			end

			local function tryBegin()
				local p = B.begin.part[stack:get_name()]
				if not p then return nil end
				if type(p) == 'function' then
					p = p(stack, node, point)
					if p == nil then return nil end
				else
					stack:take_item(1)
				end
				minetest.rotate_and_place(ItemStack(p), luser, point, true)
				-- TODO make a noise
				return stack
			end

			return tryBuild() or tryBegin() or stack
		end;
		_starlit = {
			mass = e.mass;
			reverseEngineer = rev;
			recover = e.recover or e.fab;
		};
	})
	if e.fab then
................................................................................
			};
			rarity = e.rarity or 0;
		})
	end

end)















































function B.pathLink(from, kind, what, to)
	if not B.path[from] then
		B.path[from] = {part={}, tool={}}
	end
	local k = B.path[from][kind]
	assert(k[what] == nil, 'attempted to overwrite an existing build path')
	k[what] = to
end

function B.pathFind(from, kind, what)
	if not B.path[from] then return nil end
	return B.path[from][kind][what]
end

B.stage.foreach('starlit:stageGen', {}, function(id, e)
	local grp = e.groups and table.copy(e.groups) or {}
	grp.stage = 1
	minetest.register_node(id, {
		description = 'Construction';
		drawtype = (e.box  and 'nodebox')
		        or (e.mesh and 'mesh')
		        or 'regular';
		paramtype  = (e.box or e.mesh or e.light) and 'light' or nil;
		paramtype2 = e.stateful or 'none';
		tiles = e.tex;
		node_box = e.box;
		mesh = e.mesh;
		groups = grp;
		_starlit = {
			stage = id;
		};
	})
	if e.begin then
		for _, kind in ipairs {'part', 'tool'} do
			for i, v in ipairs(e.begin[kind] or {}) do
				assert(B.begin[kind][v] == nil, 'attempted to overwrite buildpath beginning')
				B.begin[kind][v] = id
			end
		end
	end
	if e.build then
		for _, kind in ipairs {'part', 'tool'} do
			for what, to in pairs(e.build[kind] or {}) do
				B.pathLink(id, kind, what, to)
			end
		end
	end
end)


starlit.include 'parts'
starlit.include 'stages'