From 68ea0acbd0cb6dc61b849efab4d6207bdf515853 Mon Sep 17 00:00:00 2001 From: Zefram <zefram@fysh.org> Date: Wed, 09 Jul 2014 09:17:43 +0200 Subject: [PATCH] Consistently use cable in electric machine recipes --- technic/machines/LV/music_player.lua | 57 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 34 insertions(+), 23 deletions(-) diff --git a/technic/machines/LV/music_player.lua b/technic/machines/LV/music_player.lua index c850d7f..9ab88f2 100644 --- a/technic/machines/LV/music_player.lua +++ b/technic/machines/LV/music_player.lua @@ -1,19 +1,23 @@ -- LV Music player. -- The player can play music. But it is high ampage! +local S = technic.getter + minetest.register_alias("music_player", "technic:music_player") minetest.register_craft({ output = 'technic:music_player', recipe = { - {'group:wood', 'group:wood', 'group:wood'}, - {'default:diamond', 'default:diamond', 'default:diamond'}, - {'default:stone', 'default:copper_ingot', 'default:stone'}, + {'group:wood', 'default:diamond', 'group:wood'}, + {'default:diamond', 'technic:machine_casing', 'default:diamond'}, + {'default:stone', 'technic:lv_cable0', 'default:stone'}, } }) +local music_handles = {} + local music_player_formspec = "invsize[8,9;]".. - "label[0,0;Music Player]".. + "label[0,0;"..S("%s Music Player"):format("LV").."]".. "button[4,1;1,1;track1;1]".. "button[5,1;1,1;track2;2]".. "button[6,1;1,1;track3;3]".. @@ -25,24 +29,30 @@ "button[6,3;1,1;track9;9]".. "button[4,4;1,2;play;Play]".. "button[6,4;1,2;stop;Stop]".. - "label[4,0;Current track --]" + "label[4,0;"..S("Current track %s"):format("--").."]" + +local function play_track(pos, track) + return minetest.sound_play("technic_track"..tostring(track), + {pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,}) +end minetest.register_node("technic:music_player", { - description = "Music Player", + description = S("%s Music Player"):format("LV"), tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("infotext", "Music Player") + meta:set_string("infotext", S("%s Music Player"):format("LV")) meta:set_int("active", 0) meta:set_int("current_track", 1) meta:set_string("formspec", music_player_formspec) end, on_receive_fields = function(pos, formanme, fields, sender) local meta = minetest.get_meta(pos) - local music_handle = meta:get_int("music_handle") + local pos_hash = minetest.hash_node_position(pos) + local music_handle = music_handles[pos_hash] local current_track = meta:get_int("current_track") if fields.track1 then current_track = 1 end if fields.track2 then current_track = 2 end @@ -56,7 +66,7 @@ meta:set_int("current_track", current_track) meta:set_string("formspec", "invsize[8,9;]".. - "label[0,0;Music Player]".. + "label[0,0;"..S("%s Music Player"):format("LV").."]".. "button[4,1;1,1;track1;1]".. "button[5,1;1,1;track2;2]".. "button[6,1;1,1;track3;3]".. @@ -68,12 +78,13 @@ "button[6,3;1,1;track9;9]".. "button[4,4;1,2;play;Play]".. "button[6,4;1,2;stop;Stop]".. - "label[4,0;Current track " - ..current_track.."]") + "label[4,0;"..S("Current track %s") + :format(current_track).."]") if fields.play then if music_handle then minetest.sound_stop(music_handle) end + music_handle = play_track(pos, current_track) meta:set_int("active", 1) end if fields.stop then @@ -82,7 +93,7 @@ minetest.sound_stop(music_handle) end end - meta:set_int("music_handle", music_handle) + music_handles[pos_hash] = music_handle end, }) @@ -93,12 +104,13 @@ action = function(pos, node, active_object_count, active_object_count_wider) local meta = minetest.get_meta(pos) local eu_input = meta:get_int("LV_EU_input") - local machine_name = "Music Player" + local machine_name = S("%s Music Player"):format("LV") local machine_node = "technic:music_player" local demand = 150 - local music_handle = meta:get_int("music_handle") local current_track = meta:get_int("current_track") + local pos_hash = minetest.hash_node_position(pos) + local music_handle = music_handles[pos_hash] -- Setup meta data if it does not exist. if not eu_input then @@ -111,25 +123,24 @@ technic.switching_station_timeout_count(pos, "LV") if meta:get_int("active") == 0 then - meta:set_string("infotext", machine_name.." Idle") + meta:set_string("infotext", S("%s Idle"):format(machine_name)) meta:set_int("LV_EU_demand", 0) - if music_handle then - minetest.sound_stop(music_handle) - end return end if eu_input < demand then - meta:set_string("infotext", machine_name.." Unpowered") + meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) if music_handle then minetest.sound_stop(music_handle) + music_handle = nil end elseif eu_input >= demand then - meta:set_string("infotext", machine_name.." Active") - music_handle = minetest.sound_play("technic_track"..current_track, - {pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,}) - meta:set_int("music_handle", music_handle) + meta:set_string("infotext", S("%s Active"):format(machine_name)) + if not music_handle then + music_handle = play_track(pos, current_track) + end end + music_handles[pos_hash] = music_handle meta:set_int("LV_EU_demand", demand) end }) -- Gitblit v1.8.0