summaryrefslogtreecommitdiff
path: root/labels/init.lua
blob: 29e12a709fd949b81f72b57dcd59470e17610741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
--[[
	StreetsMod: All kinds of asphalt with labels
]]

labels = {}

labels.printer = {}

labels.printer.marktypes = {}

function labels.printer.can_dig(pos)
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	return (inv:is_empty("whitecart") and inv:is_empty("yellowcart") and inv:is_empty("paper"))
end

function labels.printer.checksupplies(pos)
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	local whitecart = inv:get_stack("whitecart",1)
	local yellowcart = inv:get_stack("yellowcart",1)
	local paper = inv:get_stack("paper",1)
	if not whitecart:to_table() or not yellowcart:to_table() or not paper:to_table() then
		return false
	end
	local whitecart_good = whitecart:to_table().name == "streets:whitecartridge" and whitecart:to_table().wear < 60000
	local yellowcart_good = yellowcart:to_table().name == "streets:yellowcartridge" and yellowcart:to_table().wear < 60000
	local paper_good = paper:to_table().name == "default:paper"
	local good = yellowcart_good and whitecart_good and paper_good
	return good
end

function labels.printer.nom(pos,color,amount)
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	local whitecart = inv:get_stack("whitecart",1)
	local yellowcart = inv:get_stack("yellowcart",1)
	local paper = inv:get_stack("paper",1)
	if color == "white" then
		whitecart:add_wear(amount*1000)
	elseif color == "yellow" then
		yellowcart:add_wear(amount*1000)
	end
	paper:take_item(1)
	inv:set_stack("yellowcart",1,yellowcart)
	inv:set_stack("whitecart",1,whitecart)
	inv:set_stack("paper",1,paper)
end

function labels.printer.populateoutput(pos)
	local typescount = #labels.printer.marktypes
	local pagesize = 8*5
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	local page = meta:get_int("page")
	local maxpage = math.ceil(typescount/pagesize)
	inv:set_list("output",{})
	inv:set_size("output", typescount)
	if labels.printer.checksupplies(pos) then
		for k,v in ipairs(labels.printer.marktypes) do
			inv:set_stack("output",k,v.name)
		end
	end
	meta:set_string("formspec", "size[11,10]"..
			"label[0,0;Yellow\nCartridge]" ..
			"list[current_name;yellowcart;1.5,0;1,1;]" ..
			"label[0,1;White\nCartridge]" ..
			"list[current_name;whitecart;1.5,1;1,1;]" ..
			"label[0,2;Paper]" ..
			"list[current_name;paper;1.5,2;1,1;]" ..
			"list[current_name;output;2.8,0;8,5;"..tostring((page-1)*pagesize).."]" ..
			"list[current_player;main;1.5,6.25;8,4;]"..
			"button[4,5;1,1;prevpage;<<<]"..
			"button[7,5;1,1;nextpage;>>>]"..
			"label[5.25,5.25;Page "..page.." of "..maxpage.."]")
	meta:set_int("maxpage",maxpage)
end

function labels.printer.on_construct(pos)
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	meta:set_int("page",1)
	meta:set_int("maxpage",1)
	inv:set_size("yellowcart", 1)
	inv:set_size("whitecart", 1)
	inv:set_size("paper", 1)
	labels.printer.populateoutput(pos)
end

function labels.printer.on_receive_fields(pos, formname, fields, sender)
	local meta = minetest.get_meta(pos)
	local page = meta:get_int("page")
	local maxpage = meta:get_int("maxpage")
	if fields.prevpage then
		page = page - 1
		if page < 1 then
			page = maxpage
		end
		meta:set_int("page",page)
	elseif fields.nextpage then
		page = page + 1
		if page > maxpage then
			page = 1
		end
		meta:set_int("page",page)
	end
	labels.printer.populateoutput(pos)
end

function labels.printer.allow_metadata_inventory_put(pos, listname, index, stack, player)
	if listname == "yellowcart" then
		if stack:get_name() == "streets:yellowcartridge" then
			return 1
		else
			return 0
		end
	elseif listname == "whitecart" then
		if stack:get_name() == "streets:whitecartridge" then
			return 1
		else
			return 0
		end
	elseif listname == "paper" then
		if stack:get_name() == "default:paper" then
			return stack:get_count()
		else
			return 0
		end
	else
		return 0
	end
end

function labels.printer.on_metadata_inventory_put(pos)
	labels.printer.populateoutput(pos)
end

function labels.printer.on_metadata_inventory_take(pos, listname, index)
	if listname == "output" then
		local cost = labels.printer.marktypes[index].inkamt
		local color = labels.printer.marktypes[index].color
		labels.printer.nom(pos,color,cost)
	end
	labels.printer.populateoutput(pos)
end

function labels.printer.allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
	return 0
end

minetest.register_tool(":streets:yellowcartridge",{
	description = "Yellow Ink Cartridge",
	inventory_image = "streets_yellow_cartridge.png"
	}
)

minetest.register_tool(":streets:whitecartridge",{
	description = "White Ink Cartridge",
	inventory_image = "streets_white_cartridge.png"
	}
)

minetest.register_craft({
	output = "streets:yellowcartridge",
	recipe =       {{"homedecor:plastic_sheeting","homedecor:plastic_sheeting","homedecor:plastic_sheeting"},
			{"homedecor:plastic_sheeting","dye:yellow","homedecor:plastic_sheeting"},
			{"homedecor:plastic_sheeting","",""}}
})

minetest.register_craft({
	output = "streets:whitecartridge",
	recipe =       {{"homedecor:plastic_sheeting","homedecor:plastic_sheeting","homedecor:plastic_sheeting"},
			{"homedecor:plastic_sheeting","dye:white","homedecor:plastic_sheeting"},
			{"homedecor:plastic_sheeting","",""}}
})

minetest.register_craft({
	output = "streets:yellowcartridge",
	type = "shapeless",
	recipe =       {"streets:yellowcartridge","dye:yellow"}
})

minetest.register_craft({
	output = "streets:whitecartridge",
	type = "shapeless",
	recipe =       {"streets:whitecartridge","dye:white"}
})

minetest.register_craft({
	output = "streets:printer",
	recipe =       {{"","homedecor:plastic_sheeting","homedecor:power_crystal"},
			{"homedecor:motor","default:steel_ingot","group:wool"},
			{"","homedecor:plastic_sheeting","homedecor:motor"}}
})

minetest.register_node(":streets:printer", {
	description = "Road Markings Printer",
	inventory_image = "streets_printer_inv.png",
	tiles = {"streets_printer_t.png","streets_printer_bt.png","streets_printer_l.png",
			"streets_printer_r.png","streets_printer_b.png","streets_printer_f.png"},
	paramtype = "light",
	paramtype2 = "facedir",
	walkable = true,
	groups = {snappy=3},
	sound = default.node_sound_wood_defaults(),
	drawtype = "nodebox",
	on_construct = labels.printer.on_construct,
	allow_metadata_inventory_put = labels.printer.allow_metadata_inventory_put,
	on_metadata_inventory_put = labels.printer.on_metadata_inventory_put,
	on_metadata_inventory_take = labels.printer.on_metadata_inventory_take,
	allow_metadata_inventory_move = labels.printer.allow_metadata_inventory_move,
	on_receive_fields = labels.printer.on_receive_fields,
	can_dig = labels.printer.can_dig,
	node_box = {
		type = "fixed",
		fixed = {
			{-0.4375, -0.3125, -0.125, 0.4375, -0.0625, 0.375},
			{-0.4375, -0.5, -0.125, 0.4375, -0.4375, 0.375},
			{-0.4375, -0.5, -0.125, -0.25, -0.0625, 0.375},
			{0.25, -0.5, -0.125, 0.4375, -0.0625, 0.375},
			{-0.4375, -0.5, -0.0625, 0.4375, -0.0625, 0.375},
			{-0.375, -0.4375, 0.25, 0.375, -0.0625, 0.4375},
			{-0.25, -0.25, 0.4375, 0.25, 0.0625, 0.5},
			{-0.25, -0.481132, -0.3125, 0.25, -0.4375, 0}
		},
	},
})

streets.register_label = function(friendlyname,name,tex,color,ink_needed,hide)
	local groups = {snappy = 3,attached_node = 1,oddly_breakable_by_hand = 1}
	if hide then groups.not_in_creative_inventory = 1 end
	minetest.register_node(":streets:mark_"..name,{
		description = streets.S("Marking Overlay: "..friendlyname),
		tiles = {tex,"streets_rw_transparent.png"},
		drawtype = "nodebox",
		paramtype = "light",
		paramtype2 = "facedir",
		groups = groups,
		sunlight_propagates = true,
		walkable = false,
		inventory_image = tex,
		wield_image = tex,
		after_place_node = function(pos)
			local node = minetest.get_node(pos)
			local lower_pos = {x = pos.x, y = pos.y-1, z = pos.z}
			local lower_node = minetest.get_node(lower_pos)
			if lower_node.name == "streets:asphalt" then
				lower_node.name = "streets:mark_"..(node.name:sub(14)).."_on_asphalt"
				lower_node.param2 = node.param2
				minetest.set_node(lower_pos,lower_node)
				minetest.remove_node(pos)
			end
		end,				
		node_box = {
			type = "fixed",
			fixed = {-0.5,-0.5,-0.5,0.5,-0.499,0.5}
		},
		selection_box = {
			type = "fixed",
			fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}
		}
	})

	minetest.register_node(":streets:mark_"..name.."_on_asphalt",{
		description = streets.S("Asphalt With Marking: "..friendlyname),
		groups = {cracky=3},
		tiles = {"streets_asphalt.png^"..tex,"streets_asphalt.png","streets_asphalt.png","streets_asphalt.png","streets_asphalt.png^"..tex.."^[transformR180","streets_asphalt.png^"..tex},
		paramtype2 = "facedir"
	})

	minetest.register_craft({
		output = "streets:mark_"..name.."_on_asphalt",
		type = "shapeless",
		recipe = {"streets:asphalt","streets:mark_"..name}
	})

	if minetest.get_modpath("moreblocks") then
		stairsplus:register_all("streets", name, "streets:mark_"..name.."_on_asphalt", {
			description = "Asphalt with Marking: "..friendlyname,
			tiles = {"streets_asphalt.png^"..tex,"streets_asphalt.png","streets_asphalt.png","streets_asphalt.png","streets_asphalt.png^"..tex.."^[transformR180","streets_asphalt.png^"..tex},
			groups = {cracky=3}
		})
	end
	local printdata = {name="streets:mark_"..name,color=color,inkamt=ink_needed}
	table.insert(labels.printer.marktypes,printdata)
end


--White Markings
streets.register_label("All-White","all_white","streets_all_white.png","white",9)

streets.register_label("Solid White Side Line","solid_white_side_line","streets_asphalt_side.png","white",3)

minetest.register_alias("streets:asphalt_side","streets:mark_solid_white_side_line_on_asphalt")
minetest.register_alias("streets:asphalt_sideline","streets:mark_solid_white_side_line_on_asphalt")

streets.register_label("Solid White Side Line (rotated)","solid_white_side_line_rotated","streets_asphalt_side.png^[transformR180","white",3,true)

minetest.register_alias("streets:asphalt_sideline_r","streets:mark_solid_white_side_line_rotated_on_asphalt")


streets.register_label("Solid White Center Line","solid_white_center_line","streets_asphalt_solid_line.png","white",2)

minetest.register_alias("streets:asphalt_middle","streets:mark_solid_white_center_line_on_asphalt")
minetest.register_alias("streets:asphalt_solid_line","streets:mark_solid_white_center_line_on_asphalt")


streets.register_label("Dashed White Center Line","dashed_white_center_line","streets_asphalt_dashed_line.png","white",1)

minetest.register_alias("streets:asphalt_middle_dashed","streets:mark_dashed_white_center_line_on_asphalt")
minetest.register_alias("streets:asphalt_dashed_line","streets:mark_dashed_white_center_line_on_asphalt")


streets.register_label("Solid White Side Line (corner)","solid_white_side_line_corner","streets_asphalt_outer_edge.png","white",4)

minetest.register_alias("streets:asphalt_outer_edge","streets:mark_solid_white_side_line_corner_on_asphalt")


streets.register_label("Solid White Side Line (corner, rotated)","solid_white_side_line_corner_rotated","streets_asphalt_outer_edge.png^[transformR270","white",4,true)

minetest.register_alias("streets:asphalt_outer_edge_r","streets:mark_solid_white_side_line_corner_rotated_on_asphalt")


streets.register_label("Parking (white)","white_parking","streets_parking.png","white",4)

minetest.register_alias("streets:asphalt_parking","streets:mark_white_parking_on_asphalt")


streets.register_label("White Arrow (straight)","white_arrow_straight","streets_arrow_straight.png","white",3)

minetest.register_alias("streets:asphalt_arrow_straight","streets:mark_white_arrow_straight_on_asphalt")


streets.register_label("White Arrow (left)","white_arrow_left","streets_arrow_left.png","white",3)

minetest.register_alias("streets:asphalt_arrow_left","streets:mark_white_arrow_left_on_asphalt")


streets.register_label("White Arrow (right)","white_arrow_right","streets_arrow_right.png","white",3)

minetest.register_alias("streets:asphalt_arrow_right","streets:mark_white_arrow_right_on_asphalt")


streets.register_label("White Arrow (left+straight)","white_arrow_left_straight","streets_arrow_straight_left.png","white",4)

minetest.register_alias("streets:asphalt_arrow_straight_left","streets:mark_white_arrow_left_straight_on_asphalt")


streets.register_label("White Arrow (straight+right)","white_arrow_straight_right","streets_arrow_straight_right.png","white",4)

minetest.register_alias("streets:asphalt_arrow_straight_right","streets:mark_white_arrow_straight_right_on_asphalt")


streets.register_label("White Arrow (left+straight+right)","white_arrow_left_straight_right","streets_arrow_alldirs.png","white",5)

minetest.register_alias("streets:asphalt_arrow_alldirs","streets:mark_white_arrow_left_straight_right_on_asphalt")


--Yellow streetsmod markings

streets.register_label("Solid Yellow Center Line","solid_yellow_center_line","streets_rw_solid_line.png","yellow",3)

minetest.register_alias("streets:rw_asphalt_solid","streets:mark_solid_yellow_center_line")


streets.register_label("Dashed Yellow Center Line","dashed_yellow_center_line","streets_rw_dashed_line.png","yellow",2)

minetest.register_alias("streets:rw_asphalt_dashed","streets:mark_dashed_yellow_center_line")


streets.register_label("Yellow X","yellow_x","streets_rw_cross.png","yellow",3)

minetest.register_alias("streets:rw_cross","streets:mark_yellow_x")


streets.register_label("Solid Yellow Side Line (corner)","solid_yellow_side_line_corner","streets_rw_outer_edge.png","yellow",4)

minetest.register_alias("streets:rw_outer_edge","streets:solid_yellow_side_line_corner")


streets.register_label("Solid Yellow Side Line (corner,rotated)","solid_yellow_side_line_corner_rotated","streets_rw_outer_edge.png^[transformR270","yellow",5,true)

minetest.register_alias("streets:rw_outer_edge","streets:solid_yellow_side_line_corner")


streets.register_label("Parking (yellow)","yellow_parking","streets_rw_parking.png","yellow",4)

minetest.register_alias("streets:rw_parking","streets:mark_yellow_parking")


streets.register_label("Yellow Arrow (straight)","yellow_arrow_straight","streets_rw_arrow_straight.png","yellow",3)

minetest.register_alias("streets:rw_straight","streets:mark_yellow_arrow_straight")


streets.register_label("Yellow Arrow (left)","yellow_arrow_left","streets_rw_arrow_left.png","yellow",3)

minetest.register_alias("streets:rw_left","streets:mark_yellow_arrow_left")


streets.register_label("Yellow Arrow (right)","yellow_arrow_right","streets_rw_arrow_right.png","yellow",3)

minetest.register_alias("streets:rw_right","streets:mark_yellow_arrow_right")


streets.register_label("Yellow Arrow (left+straight)","yellow_arrow_left_straight","streets_rw_arrow_straight_left.png","yellow",4)

minetest.register_alias("streets:rw_straight_left","streets:mark_yellow_arrow_left_straight")


streets.register_label("Yellow Arrow (straight+right)","yellow_arrow_straight_right","streets_rw_arrow_straight_right.png","yellow",4)

minetest.register_alias("streets:rw_straight_right","streets:mark_yellow_arrow_straight_right")


streets.register_label("Yellow Arrow (left+straight+right)","yellow_arrow_left_straight_right","streets_rw_arrow_alldirs.png","yellow",5)

minetest.register_alias("streets:rw_alldirs","streets:mark_yellow_arrow_left_straight_right")

streets.register_label("Solid Yellow Side Line","solid_yellow_side_line","streets_rw_asphalt_side.png","yellow",3)

minetest.register_alias("streets:rw_sideline","streets:mark_solid_yellow_side_line")

streets.register_label("Solid Yellow Side Line (rotated)","solid_yellow_side_line_rotated","streets_rw_asphalt_side.png^[transformR180","yellow",3,true)

streets.register_label("Yellow Diagonal Lines","yellow_diagonal","streets_yellow_diagonal_lines.png","yellow",5)

--Infrastructure markings

streets.register_label("Solid Yellow Center Line (wide)","solid_yellow_center_line_wide","infrastructure_single_yellow_line.png","yellow",4)

minetest.register_alias("infrastructure:asphalt_center_solid_line","streets:mark_solid_yellow_center_line_wide_on_asphalt")


streets.register_label("Solid Yellow Center Line (wide,offset)","solid_yellow_center_line_wide_offset","infrastructure_solid_yellow_line_one_side.png","yellow",4)

minetest.register_alias("infrastructure:asphalt_center_solid_one_side","streets:mark_solid_yellow_center_line_wide_offset_on_asphalt")


streets.register_label("Double Yellow Center Line (wide)","double_yellow_center_line_wide","infrastructure_double_yellow_line.png","yellow",6)

minetest.register_alias("infrastructure:asphalt_center_solid_double","streets:mark_double_yellow_center_line_wide_on_asphalt")


streets.register_label("Solid Yellow Center Line (wide,corner)","solid_yellow_center_line_wide_corner","infrastructure_single_yellow_line_corner.png","yellow",4)

minetest.register_alias("infrastructure:asphalt_center_corner_single","streets:mark_solid_yellow_center_line_wide_corner_on_asphalt")


streets.register_label("Double Yellow Center Line (wide,corner)","double_yellow_center_line_wide_corner","infrastructure_solid_double_yellow_line_corner.png","yellow",6)

minetest.register_alias("infrastructure:asphalt_center_corner_double","streets:mark_double_yellow_center_line_wide_corner_on_asphalt")


minetest.register_alias("infrastructure:asphalt_arrow_straight", "streets:asphalt_arrow_straight")


minetest.register_alias("infrastructure:asphalt_arrow_straight_left", "streets:asphalt_arrow_straight_left")


minetest.register_alias("infrastructure:asphalt_arrow_straight_right", "streets:asphalt_arrow_straight_left")


minetest.register_alias("infrastructure:asphalt_arrow_left", "streets:asphalt_arrow_left")


minetest.register_alias("infrastructure:asphalt_arrow_right", "streets:asphalt_arrow_right")


minetest.register_alias("infrastructure:asphalt_parking", "streets:asphalt_parking")