Skip to content

Commit

Permalink
Using Cached Sounds;
Browse files Browse the repository at this point in the history
Using local Translate/Rotate To;
Fixed infinity image not showing up;
Removed JSON parsers/stringifiers;
Trace ignore self character;
  • Loading branch information
gtnardy committed Sep 21, 2022
1 parent a7cf860 commit a02da9b
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 54 deletions.
6 changes: 5 additions & 1 deletion Client/Index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Input.Register("SpawnMenu", "Q")
Input.Register("ContextMenu", "C")
Input.Register("Undo", "X")

-- Hit Taken Feedback Sound Cached
SoundHitTakenFeedback = Sound(Vector(), "nanos-world::A_HitTaken_Feedback", true, false, SoundType.SFX, 1, 1, 400, 3600, 0, false, 0, false)


-- When LocalPlayer spawns, sets an event on it to trigger when we possesses a new character, to store the local controlled character locally. This event is only called once, see Package.Subscribe("Load") to load it when reloading a package
Client.Subscribe("SpawnLocalPlayer", function(local_player)
local_player:Subscribe("Possess", function(player, character)
Expand Down Expand Up @@ -64,7 +68,7 @@ function UpdateLocalCharacter(character)
character:Subscribe("HealthChanged", function(charac, old_health, new_health)
-- Plays a Hit Taken sound effect if took damage
if (new_health < old_health) then
Sound(Vector(), "nanos-world::A_HitTaken_Feedback", true)
SoundHitTakenFeedback:Play()
end

-- Immediatelly Updates the Health UI
Expand Down
6 changes: 5 additions & 1 deletion Client/Notifications.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- Sounds Cached
SoundNotification = Sound(Vector(), "nanos-world::A_VR_Click_01", true, false, SoundType.UI, 0.1, 1, 400, 3600, 0, false, 0, false)


-- Adds the Notification on the Screen
---@param id string Unique ID used to store if the notification was already displayed to the player
---@param message string The message to display
Expand All @@ -17,7 +21,7 @@ function AddNotification(id, message, time, delay, force)
end

-- Plays a sound
Sound(Vector(), "nanos-world::A_VR_Click_01", true, true, SoundType.SFX, 0.1, 1)
SoundNotification:Play()

-- Trigger WebUI to display it
MainHUD:CallEvent("AddNotification", _message, _time)
Expand Down
29 changes: 20 additions & 9 deletions Client/SpawnMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ SpawnMenuOpened = SpawnMenuOpened or false
Client.SetHighlightColor(Color(0, 20, 0, 1.20), 0, HighlightMode.Always) -- Index 0
Client.SetOutlineColor(Color(0, 0, 300), 2) -- Index 2

-- Caches Sounds with Auto Play = false
SoundDeleteItemFromHistory = Sound(Vector(), "nanos-world::A_Player_Eject", true, false, SoundType.UI, 0.1, 1, 400, 3600, 0, false, 0, false)
SoundButtonHover = Sound(Vector(), "nanos-world::A_Button_Hover_Cue", true, false, SoundType.UI, 1, 1, 400, 3600, 0, false, 0, false)
SoundButtonClick = Sound(Vector(), "nanos-world::A_Button_Click_Cue", true, false, SoundType.UI, 1, 1, 400, 3600, 0, false, 0, false)
SoundSpawnItem = Sound(Vector(), "nanos-world::A_Button_Click_Up_Cue", true, false, SoundType.UI, 1, 1.1, 400, 3600, 0, false, 0, false)
SoundSelectOption = Sound(Vector(), "nanos-world::A_Button_Click_Up_Cue", true, false, SoundType.UI, 1, 1.1, 400, 3600, 0, false, 0, false)
SoundInvalidAction = Sound(Vector(), "nanos-world::A_Invalid_Action", true, false, SoundType.UI, 1, 1, 400, 3600, 0, false, 0, false)


Package.Subscribe("Load", function()
-- Wait 1 second so all other packages can send their Tools during Package Load event
Timer.SetTimeout(function()
Expand Down Expand Up @@ -54,7 +63,7 @@ Package.Subscribe("Load", function()
-- Iterate each group to add to Spawn Menu, this will add all items to it
-- If an item is added after this it will not be added to spawn menu
for group, spawn_menu_group_data in pairs(SpawnMenuItems) do
MainHUD:CallEvent("AddSpawnMenuGroup", group, JSON.stringify(spawn_menu_group_data))
MainHUD:CallEvent("AddSpawnMenuGroup", group, spawn_menu_group_data)
end
end, 1000)
end)
Expand Down Expand Up @@ -90,7 +99,7 @@ function DeleteItemFromHistory()
-- If there is a item to destroy, otherwise tries the next from the list, recursively
if (data.item and data.item:IsValid()) then
Events.CallRemote("DestroyItem", data.item)
Sound(Vector(), "nanos-world::A_Player_Eject", true, true, SoundType.SFX, 0.1)
SoundDeleteItemFromHistory:Play()
else
DeleteItemFromHistory()
end
Expand Down Expand Up @@ -127,11 +136,13 @@ end)

-- Sound when hovering an Item in the SpawnMenu
MainHUD:Subscribe("HoverSound", function(pitch)
Sound(Vector(), "nanos-world::A_Button_Hover_Cue", true, true, SoundType.SFX, 1, pitch or 1)
SoundButtonHover:SetPitch(pitch or 1)
SoundButtonHover:Play()
end)

MainHUD:Subscribe("ClickSound", function(pitch)
Sound(Vector(), "nanos-world::A_Button_Click_Cue", true, true, SoundType.SFX, 1, pitch or 1)
SoundButtonClick:SetPitch(pitch or 1)
SoundButtonClick:Play()
end)

-- Handle for selecting an Item from the SpawnMenu
Expand All @@ -145,7 +156,7 @@ MainHUD:Subscribe("SpawnItem", function(group, category, asset_id)
local end_location = viewport_3D.Position + viewport_3D.Direction * trace_max_distance

-- Traces for world things
local trace_result = Client.TraceLineSingle(start_location, end_location, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic)
local trace_result = Client.TraceLineSingle(start_location, end_location, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.Water)

local spawn_location = end_location

Expand All @@ -165,7 +176,7 @@ MainHUD:Subscribe("SpawnItem", function(group, category, asset_id)
Events.CallRemote("SpawnItem", group, category, asset_id, spawn_location, spawn_rotation, SelectedOption)

-- Spawns a sound for 'spawning an item'
Sound(Vector(), "nanos-world::A_Button_Click_Up_Cue", true, true, SoundType.SFX, 1, 1.1)
SoundSpawnItem:Play()
end)

-- Subscribes for when I select an Option
Expand All @@ -177,7 +188,7 @@ MainHUD:Subscribe("SelectOption", function(texture_path)
if (local_character) then
local current_picked_item = local_character:GetPicked()
if (current_picked_item) then
Sound(Vector(), "nanos-world::A_Button_Click_Up_Cue", true, true, SoundType.SFX, 1, 1.1)
SoundSelectOption:Play()
Events.CallRemote("ApplyWeaponPattern", current_picked_item, texture_path)
end
end
Expand Down Expand Up @@ -272,7 +283,7 @@ function TraceFor(trace_max_distance, collision_channel)
local start_location = viewport_3D.Position + viewport_3D.Direction * 100
local end_location = viewport_3D.Position + viewport_3D.Direction * trace_max_distance

return Client.TraceLineSingle(start_location, end_location, collision_channel, TraceMode.TraceComplex | TraceMode.ReturnEntity)
return Client.TraceLineSingle(start_location, end_location, collision_channel, TraceMode.TraceComplex | TraceMode.ReturnEntity, { Client.GetLocalPlayer():GetControlledCharacter() })
end

-- Adds a new item to the Spawn Menu
Expand Down Expand Up @@ -309,7 +320,7 @@ function AddSpawnMenuItem(group, tab, id, name, image, category, tutorials)
table.insert(tutorials_parsed, { image = key_icon, text = tutorial_data.text })
end

ToolGunsTutorials[id] = { tutorials = JSON.stringify(tutorials_parsed), name = name }
ToolGunsTutorials[id] = { tutorials = tutorials_parsed, name = name }
end
end

Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Balloon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function HandleBalloonTool(weapon)
Events.CallRemote("SpawnBalloon", trace_result.Location, trace_result.Normal:Rotation(), force, max_length, trace_result.Entity, distance_trace_object)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)

Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function HandleColorTool(tool)
Events.CallRemote("ColorObject", trace_result.Entity, trace_result.Location, trace_result.Normal, color)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Lamp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function HandleLampTool(weapon)
Events.CallRemote("SpawnLamp", trace_result.Location, relative_location, relative_rotation, trace_result.Normal, trace_result.Entity)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function HandleLightTool(weapon)
Events.CallRemote("SpawnLight", trace_result.Location, trace_result.Normal, trace_result.Entity, distance_trace_object)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)

Expand Down
11 changes: 9 additions & 2 deletions Client/Tools/PhysicsGun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ Timer.SetInterval(function()
if (PhysicsGun.picking_object == nil) then return end
end

-- If lost network authority somehow, stops gravitating it
if (not PhysicsGun.picking_object:HasNetworkAuthority()) then
TogglePhysicsGunLocal(false)
return
end

-- Otherwise, if I'm grabbing something, tells the server to update it's location

-- Get the camera location in 3D World Space
Expand All @@ -350,8 +356,9 @@ Timer.SetInterval(function()
rotation = RoundRotator(rotation, 45)
end

-- Calls remote to update it's location
Events.CallRemote("UpdateObjectPosition", PhysicsGun.picking_object, end_location, rotation)
-- Updates it's location (it is only possible to call those methods as this Player is the network authority)
PhysicsGun.picking_object:TranslateTo(end_location, 0.05)
PhysicsGun.picking_object:RotateTo(rotation, 0.1)
end
end, 0.033)

Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Remover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function HandleRemoverTool(weapon)
Events.CallRemote("DestroyItem", trace_result.Entity)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Resizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function ResizerFire(weapon, shooter)
Events.CallRemote("ToggleResizing", true)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end

Expand Down
4 changes: 2 additions & 2 deletions Client/Tools/Rope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function HandleRopeTool(tool)
if (RopeTool.attaching_start_to) then
-- Do not allow attaching to itself
if (RopeTool.attaching_start_to == trace_result.Entity) then
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
return
end

Expand Down Expand Up @@ -50,7 +50,7 @@ function HandleRopeTool(tool)
end

-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end)
end

Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Thruster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function HandleThrusterTool(weapon)
Events.CallRemote("SpawnThruster", trace_result.Location, relative_location, relative_rotation, trace_result.Normal, trace_result.Entity)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Trail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function HandleTrailTool(weapon)
Events.CallRemote("SpawnTrail", trace_result.Location, relative_location, relative_rotation, trace_result.Normal, trace_result.Entity)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion Client/Tools/Useless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function HandleUselessTool(tool)
Events.CallRemote("UselessObject", trace_result.Entity, trace_result.Location, trace_result.Normal)
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Button_Click_Down_Cue", true, true, SoundType.SFX, 4)
SoundInvalidAction:Play()
end
end)
end
Expand Down
4 changes: 2 additions & 2 deletions Client/Tools/Weld.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function HandleWeldTool(tool)
if (WeldTool.welding_start_to) then
-- Do not allow attaching to itself
if (WeldTool.welding_start_to == trace_result.Entity) then
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
return
end

Expand Down Expand Up @@ -53,7 +53,7 @@ function HandleWeldTool(tool)
end

-- If didn't hit anything, plays a negative sound
Sound(Vector(), "nanos-world::A_Invalid_Action", true, true, SoundType.SFX, 1)
SoundInvalidAction:Play()
end)
end

Expand Down
4 changes: 2 additions & 2 deletions Client/UI/modules/spawn-menu/spawn-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function TabClick(tab_element) {
}

// Adds "all" category
DisplayCategory("all", "All", "./images/categories/infinity.png", "./images/categories/infinity-disabled.png");
DisplayCategory("all", "All", "modules/spawn-menu/images/categories/infinity.webp", "modules/spawn-menu/images/categories/infinity-disabled.webp");

// Forces click on first category
CategoryClick(document.querySelectorAll(".spawn_category")[0]);
Expand Down Expand Up @@ -273,7 +273,7 @@ function AddItem(group, item_id, item_name, image) {
}

function AddSpawnMenuGroup(group, group_data) {
spawn_menu_data[group] = JSON.parse(group_data);
spawn_menu_data[group] = group_data;

RefreshSpawnMenu();
}
Expand Down
8 changes: 3 additions & 5 deletions Client/UI/modules/tutorials/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ function ToggleTutorial(is_visible, title, tutorial_list) {
const tutorial_title = document.getElementById("tutorial_title");
tutorial_title.innerHTML = title;

const tutorial_list_json = JSON.parse(tutorial_list);

for (let tutorial in tutorial_list_json) {
let image = tutorial_list_json[tutorial].image;
let text = tutorial_list_json[tutorial].text;
for (let tutorial in tutorial_list) {
let image = tutorial_list[tutorial].image;
let text = tutorial_list[tutorial].text;

const tutorial_item_image = document.createElement("img");
tutorial_item_image.classList.add("tutorial_key");
Expand Down
14 changes: 7 additions & 7 deletions Package.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# package configurations
[package]
# package name
name = "Sandbox"
name = "Sandbox"
# contributors
author = "nanos™"
author = "nanos™"
# version
version = "2.13.1"
version = "2.14.0"
# image URL
image = "https://i.imgur.com/aoEa4N4.jpg"
image = "https://i.imgur.com/aoEa4N4.jpg"
# package type: 'script' (normal package), 'game-mode' (unique package - can only load one at a time), 'library' (doesn't start a Lua VM) or 'loading-screen' (special package for loading screen)
type = "game-mode"
type = "game-mode"
# whether to force the custom map script to do not load
force_no_map_script = false
force_no_map_script = false
# auto destroy all entities spawned by this package when it unloads
auto_cleanup = true
auto_cleanup = true
# packages requirements
packages_requirements = [

Expand Down
14 changes: 0 additions & 14 deletions Server/Tools/PhysicsGun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ Events.Subscribe("PickUp", function(player, weapon, object, is_grabbing, picking
Events.BroadcastRemote("PickUpObject", object, is_grabbing)
end)

-- Subscribe for Client's custom event, to update the position of the object he is grabbing
Events.Subscribe("UpdateObjectPosition", function(player, object, location, rotation)
-- Maybe the server is closing?
if (not object) then return end

object:TranslateTo(location, 0.05)
object:RotateTo(rotation, 0.1)

-- Only updates the Network Authority if this entity is network distributed
if (object:IsNetworkDistributed()) then
object:SetNetworkAuthority(player)
end
end)

-- Subscribes for Clients event for turning on/off the physics gun
Events.Subscribe("TogglePhysicsGun", function(player, weapon, enable)
-- Maybe the server is closing?
Expand Down

0 comments on commit a02da9b

Please sign in to comment.