forked from mtcontrib/signs_lib
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			8aafe6608c
			...
			ed3a679bca
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | ed3a679bca | ||
|  | 5ae111e1fa | ||
|  | aff005e745 | ||
|  | 3d0e8d47e6 | 
							
								
								
									
										2
									
								
								API.md
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								API.md
									
									
									
									
									
								
							| @@ -250,7 +250,7 @@ signs_lib.register_sign("basic_signs:sign_wall_glass", { | |||||||
|  |  | ||||||
| * `signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)` | * `signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)` | ||||||
|  |  | ||||||
|   Open the default sign formspec, if the player has the `signslib_edit` privilege. |   Open the default sign formspec, if the player has the `signslib_edit` privilege. (privilege can be set by `signs_lib.edit_priv` setting) | ||||||
|  |  | ||||||
| * `signs_lib.destruct_sign(pos)` | * `signs_lib.destruct_sign(pos)` | ||||||
|  |  | ||||||
|   | |||||||
| @@ -67,3 +67,4 @@ The list of loaded, sign-bearing blocks is created/populated by an LBM (and trim | |||||||
| * `signslib_edit` | * `signslib_edit` | ||||||
|  |  | ||||||
| Allows to rotate signs and to open (and consequently edit) any default sign formspec. | Allows to rotate signs and to open (and consequently edit) any default sign formspec. | ||||||
|  | (privilege can be set by `signs_lib.edit_priv` setting) | ||||||
|   | |||||||
							
								
								
									
										61
									
								
								api.lua
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								api.lua
									
									
									
									
									
								
							| @@ -1,6 +1,11 @@ | |||||||
| -- signs_lib api, backported from street_signs | -- signs_lib api, backported from street_signs | ||||||
|  |  | ||||||
| local S = signs_lib.S | local S = signs_lib.S | ||||||
|  | local has_default_mod = minetest.get_modpath("default") | ||||||
|  |  | ||||||
|  | local function log(level, messagefmt, ...) | ||||||
|  | 	minetest.log(level, "[signs_lib] " .. messagefmt:format(...)) | ||||||
|  | end | ||||||
|  |  | ||||||
| local function get_sign_formspec() end | local function get_sign_formspec() end | ||||||
|  |  | ||||||
| @@ -21,14 +26,14 @@ signs_lib.standard_xoffs = 4 | |||||||
| signs_lib.standard_yoffs = 0 | signs_lib.standard_yoffs = 0 | ||||||
| signs_lib.standard_cpl = 35 | signs_lib.standard_cpl = 35 | ||||||
|  |  | ||||||
| signs_lib.standard_wood_groups = table.copy(default and minetest.registered_items["default:sign_wall_wood"].groups or {}) | signs_lib.standard_wood_groups = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_wood"].groups or {}) | ||||||
| signs_lib.standard_wood_groups.attached_node = nil | signs_lib.standard_wood_groups.attached_node = nil | ||||||
|  |  | ||||||
| signs_lib.standard_steel_groups = table.copy(default and minetest.registered_items["default:sign_wall_steel"].groups or {}) | signs_lib.standard_steel_groups = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_steel"].groups or {}) | ||||||
| signs_lib.standard_steel_groups.attached_node = nil | signs_lib.standard_steel_groups.attached_node = nil | ||||||
|  |  | ||||||
| signs_lib.standard_wood_sign_sounds  = table.copy(default and minetest.registered_items["default:sign_wall_wood"].sounds or {}) | signs_lib.standard_wood_sign_sounds  = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_wood"].sounds or {}) | ||||||
| signs_lib.standard_steel_sign_sounds = table.copy(default and minetest.registered_items["default:sign_wall_steel"].sounds or {}) | signs_lib.standard_steel_sign_sounds = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_steel"].sounds or {}) | ||||||
|  |  | ||||||
| signs_lib.default_text_scale = {x=10, y=10} | signs_lib.default_text_scale = {x=10, y=10} | ||||||
|  |  | ||||||
| @@ -172,6 +177,9 @@ minetest.register_entity("signs_lib:text", { | |||||||
| 			self.object:remove() | 			self.object:remove() | ||||||
| 		end | 		end | ||||||
| 	end, | 	end, | ||||||
|  | 	on_blast = function(self, damage) | ||||||
|  | 		return false, false, {} | ||||||
|  | 	end, | ||||||
| }) | }) | ||||||
|  |  | ||||||
| function signs_lib.delete_objects(pos) | function signs_lib.delete_objects(pos) | ||||||
| @@ -742,6 +750,15 @@ function signs_lib.destruct_sign(pos) | |||||||
| 	signs_lib.delete_objects(pos) | 	signs_lib.delete_objects(pos) | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function signs_lib.blast_sign(pos, intensity) | ||||||
|  | 	if signs_lib.can_modify(pos, "") then | ||||||
|  | 		local node = minetest.get_node(pos) | ||||||
|  | 		local drops = minetest.get_node_drops(node, "tnt:blast") | ||||||
|  | 		minetest.remove_node(pos) | ||||||
|  | 		return drops | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
| local function make_infotext(text) | local function make_infotext(text) | ||||||
| 	text = trim_input(text) | 	text = trim_input(text) | ||||||
| 	local lines = signs_lib.split_lines_and_words(text) or {} | 	local lines = signs_lib.split_lines_and_words(text) or {} | ||||||
| @@ -803,7 +820,16 @@ end | |||||||
| function signs_lib.can_modify(pos, player) | function signs_lib.can_modify(pos, player) | ||||||
| 	local meta = minetest.get_meta(pos) | 	local meta = minetest.get_meta(pos) | ||||||
| 	local owner = meta:get_string("owner") | 	local owner = meta:get_string("owner") | ||||||
| 	local playername = player:get_player_name() | 	local playername | ||||||
|  | 	if type(player) == "userdata" then | ||||||
|  | 		playername = player:get_player_name() | ||||||
|  |  | ||||||
|  | 	elseif type(player) == "string" then | ||||||
|  | 		playername = player | ||||||
|  |  | ||||||
|  | 	else | ||||||
|  | 		playername = "" | ||||||
|  | 	end | ||||||
|  |  | ||||||
| 	if minetest.is_protected(pos, playername) then | 	if minetest.is_protected(pos, playername) then | ||||||
| 		minetest.record_protection_violation(pos, playername) | 		minetest.record_protection_violation(pos, playername) | ||||||
| @@ -812,7 +838,7 @@ function signs_lib.can_modify(pos, player) | |||||||
|  |  | ||||||
| 	if owner == "" | 	if owner == "" | ||||||
| 	  or playername == owner | 	  or playername == owner | ||||||
| 	  or (minetest.check_player_privs(playername, {signslib_edit=true})) | 	  or minetest.get_player_privs(playername)[signs_lib.edit_priv] | ||||||
| 	  or (playername == minetest.settings:get("name")) then | 	  or (playername == minetest.settings:get("name")) then | ||||||
| 		return true | 		return true | ||||||
| 	end | 	end | ||||||
| @@ -951,7 +977,7 @@ function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locke | |||||||
| end | end | ||||||
|  |  | ||||||
| function signs_lib.register_fence_with_sign() | function signs_lib.register_fence_with_sign() | ||||||
| 	minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()") | 	log("warning", "Attempt to call no longer used function signs_lib.register_fence_with_sign()") | ||||||
| end | end | ||||||
|  |  | ||||||
| local use_glow = function(pos, node, puncher, pointed_thing) | local use_glow = function(pos, node, puncher, pointed_thing) | ||||||
| @@ -984,6 +1010,7 @@ function signs_lib.register_sign(name, raw_def) | |||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node | 	def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node | ||||||
|  | 	def.on_blast         = raw_def.on_blast         or signs_lib.blast_sign | ||||||
|  |  | ||||||
| 	if raw_def.entity_info then | 	if raw_def.entity_info then | ||||||
|  |  | ||||||
| @@ -1292,7 +1319,11 @@ minetest.register_chatcommand("regen_signs", { | |||||||
| 	end | 	end | ||||||
| }) | }) | ||||||
|  |  | ||||||
| minetest.register_privilege("signslib_edit", {}) | minetest.register_on_mods_loaded(function() | ||||||
|  | 	if not minetest.registered_privileges[signs_lib.edit_priv] then | ||||||
|  | 		minetest.register_privilege("signslib_edit", {}) | ||||||
|  | 	end | ||||||
|  | end) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -1337,11 +1368,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) | |||||||
| 	local playername = player:get_player_name() | 	local playername = player:get_player_name() | ||||||
|  |  | ||||||
| 	if fields.text and fields.ok then | 	if fields.text and fields.ok then | ||||||
| 		minetest.log("action", S("@1 wrote \"@2\" to sign at @3", | 		log("action", "%s wrote %q to sign at %s", | ||||||
| 			(playername or ""), | 			(playername or ""), | ||||||
| 			fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"), | 			fields.text:gsub("\n", "\\n"), | ||||||
| 			pos_string | 			pos_string | ||||||
| 		)) | 		) | ||||||
| 		signs_lib.update_sign(pos, fields) | 		signs_lib.update_sign(pos, fields) | ||||||
| 	elseif fields.wide_on or fields.wide_off or fields.uni_on or fields.uni_off then | 	elseif fields.wide_on or fields.wide_off or fields.uni_on or fields.uni_off then | ||||||
| 		local node = minetest.get_node(pos) | 		local node = minetest.get_node(pos) | ||||||
| @@ -1365,20 +1396,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) | |||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		if change_wide then | 		if change_wide then | ||||||
| 			minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3", | 			log("action", "%s flipped the wide-font switch to %q at %s", | ||||||
| 				(playername or ""), | 				(playername or ""), | ||||||
| 				(fields.wide_on and "off" or "on"), | 				(fields.wide_on and "off" or "on"), | ||||||
| 				minetest.pos_to_string(pos) | 				minetest.pos_to_string(pos) | ||||||
| 			)) | 			) | ||||||
| 			signs_lib.update_sign(pos, fields) | 			signs_lib.update_sign(pos, fields) | ||||||
| 			minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name)) | 			minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name)) | ||||||
| 		end | 		end | ||||||
| 		if change_uni then | 		if change_uni then | ||||||
| 			minetest.log("action", S("@1 flipped the unicode-font switch to \"@2\" at @3", | 			log("action", "%s flipped the unicode-font switch to %q at %s", | ||||||
| 				(playername or ""), | 				(playername or ""), | ||||||
| 				(fields.uni_on and "off" or "on"), | 				(fields.uni_on and "off" or "on"), | ||||||
| 				minetest.pos_to_string(pos) | 				minetest.pos_to_string(pos) | ||||||
| 			)) | 			) | ||||||
| 			signs_lib.update_sign(pos, fields) | 			signs_lib.update_sign(pos, fields) | ||||||
| 			minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name)) | 			minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name)) | ||||||
| 		end | 		end | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								init.lua
									
									
									
									
									
								
							| @@ -9,6 +9,8 @@ signs_lib.path = minetest.get_modpath(minetest.get_current_modname()) | |||||||
|  |  | ||||||
| signs_lib.S = minetest.get_translator(minetest.get_current_modname()) | signs_lib.S = minetest.get_translator(minetest.get_current_modname()) | ||||||
|  |  | ||||||
|  | signs_lib.edit_priv = minetest.settings:get("signs_lib.edit_priv") or "signslib_edit" | ||||||
|  |  | ||||||
| dofile(signs_lib.path.."/encoding.lua") | dofile(signs_lib.path.."/encoding.lua") | ||||||
| dofile(signs_lib.path.."/api.lua") | dofile(signs_lib.path.."/api.lua") | ||||||
| dofile(signs_lib.path.."/standard_signs.lua") | dofile(signs_lib.path.."/standard_signs.lua") | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								settingstypes.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								settingstypes.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | signs_lib.edit_priv (Allows to rotate signs and to open (and consequently edit) any default sign formspec) string signslib_edit | ||||||
		Reference in New Issue
	
	Block a user