1 script.on_event(defines.events.on_built_entity, function(event) |
1 ---@param entity LuaEntity |
2 local sound_path = "entity-close/"..event.entity.name |
2 local function should_play_entity_sounds(entity) |
|
3 return not (entity.type == "electric-pole" or entity.type == "wall" or entity.name == "stone-furnace") |
|
4 end |
|
5 |
|
6 ---@param entity LuaEntity |
|
7 ---@param sound_path SoundPath |
|
8 local function try_play_sound(entity, sound_path, position) |
3 if helpers.is_valid_sound_path(sound_path) |
9 if helpers.is_valid_sound_path(sound_path) |
4 then |
10 then |
5 event.entity.surface.play_sound{ |
11 entity.surface.play_sound{ |
6 path=sound_path, |
12 path=sound_path, |
7 position=game.players[event.player_index].position, |
13 position=entity.position, |
8 } |
14 } |
|
15 return true |
|
16 else |
|
17 return false |
9 end |
18 end |
|
19 end |
|
20 |
|
21 local function play_drop_sounds(entity, position) |
|
22 if not (should_play_entity_sounds(entity) and try_play_sound(entity, "entity-close/"..entity.name)) |
|
23 then |
|
24 try_play_sound(entity, "item-drop/"..entity.name) |
|
25 end |
|
26 end |
|
27 |
|
28 local function play_mined_sounds(entity, position) |
|
29 if not (should_play_entity_sounds(entity) and try_play_sound(entity, "entity-open/"..entity.name, position)) |
|
30 then |
|
31 try_play_sound(entity, "item-pick/"..entity.name, position) |
|
32 end |
|
33 end |
|
34 |
|
35 script.on_event(defines.events.on_built_entity, function(event) |
|
36 play_drop_sounds(event.entity, game.players[event.player_index].position) |
10 end) |
37 end) |
11 |
38 |
12 script.on_event(defines.events.on_robot_built_entity, function(event) |
39 script.on_event(defines.events.on_robot_built_entity, function(event) |
13 local sound_path = "entity-close/"..event.entity.name |
40 play_drop_sounds(event.entity, event.entity.position) |
14 if helpers.is_valid_sound_path(sound_path) |
41 end) |
15 then |
42 |
16 event.entity.surface.play_sound{ |
43 script.on_event(defines.events.on_space_platform_built_entity, function(event) |
17 path=sound_path, |
44 play_drop_sounds(event.entity, event.entity.position) |
18 position=event.entity.position, |
|
19 } |
|
20 end |
|
21 end) |
45 end) |
22 |
46 |
23 script.on_event(defines.events.on_player_mined_entity, function(event) |
47 script.on_event(defines.events.on_player_mined_entity, function(event) |
24 local sound_path = "entity-open/"..event.entity.name |
48 play_mined_sounds(event.entity, game.players[event.player_index].position) |
25 if helpers.is_valid_sound_path(sound_path) |
|
26 then |
|
27 event.entity.surface.play_sound{ |
|
28 path=sound_path, |
|
29 position=game.players[event.player_index].position, |
|
30 } |
|
31 end |
|
32 end) |
49 end) |
33 |
50 |
34 script.on_event(defines.events.on_robot_mined_entity, function(event) |
51 script.on_event(defines.events.on_robot_mined_entity, function(event) |
35 local sound_path = "entity-open/"..event.entity.name |
52 play_mined_sounds(event.entity, event.entity.position) |
36 if helpers.is_valid_sound_path(sound_path) |
|
37 then |
|
38 event.entity.surface.play_sound{ |
|
39 path=sound_path, |
|
40 position=event.entity.position, |
|
41 } |
|
42 end |
|
43 end) |
53 end) |
|
54 |
|
55 script.on_event(defines.events.on_space_platform_mined_entity, function(event) |
|
56 play_mined_sounds(event.entity, event.entity.position) |
|
57 end) |