Skip to content

Commit

Permalink
Add keybind for Undo/Redo (shift-Z)
Browse files Browse the repository at this point in the history
Part of #7
  • Loading branch information
Nebual committed Aug 12, 2023
1 parent 652339c commit 6adcc41
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .sbproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@
"Public": true,
"ReplaceTags": "sandbox game dynamic spawnmenu physgun",
"CsProjName": "",
"ControlModes": {},
"ControlModes": {
"Keyboard": true,
"Gamepad": true
},
"InputSettings": {
"Actions": [
{
Expand Down Expand Up @@ -316,6 +319,11 @@
"Name": "Noclip",
"KeyboardCode": "N",
"GroupName": "Movement"
},
{
"Name": "Undo",
"KeyboardCode": "Z",
"GroupName": "Other"
}
]
},
Expand Down
27 changes: 26 additions & 1 deletion code/undosystem/UndoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ public static void OnAddUndo( Func<string> undoable, Entity owner )
}
}

[GameEvent.Client.BuildInput]
public static void ProcessClientInput()
{
if ( Input.Pressed( "undo" ) )
{
if ( Input.Down( "run" ) )
{
OnRedo();
}
else
{
OnUndo();
}
}
}

[ConCmd.Server( "undo" )]
public static async void OnUndo()
{
Expand Down Expand Up @@ -103,7 +119,7 @@ public static void OnRedo()
continue;
}

CreateUndoParticles( To.Single( creator ), prop.Position );
CreateRedoParticles( To.Single( creator ), prop.Position );

Redoer.OnRedone( To.Single( creator ) );
Redoer.ResetProp( redo );
Expand All @@ -128,5 +144,14 @@ public static void CreateUndoParticles( Vector3 pos )
Game.LocalPawn?.PlaySound( "drop_001" );
}
}

[ClientRpc]
public static void CreateRedoParticles( Vector3 pos )
{
using ( Prediction.Off() )
{
Game.LocalPawn?.PlaySound( "drop_002" );
}
}
}
}

0 comments on commit 6adcc41

Please sign in to comment.