Skip to content

Commit

Permalink
undo.lua: Replaced umsgs with net messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Stevens committed Jan 7, 2014
1 parent 8c16ae5 commit 228e317
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions garrysmod/lua/includes/modules/undo.lua
@@ -1,6 +1,6 @@

require ( "usermessage" )
require ( "timer" )
require ( "net" )

module( "undo", package.seeall )

Expand Down Expand Up @@ -57,18 +57,18 @@ if ( CLIENT ) then
AddUndo
Called from server. Adds a new undo to our UI
-----------------------------------------------------------]]
local function AddUndo( message )
local function AddUndo( _ )
local k = message:ReadLong();
local v = message:ReadString();
local k = net.ReadInt(16);
local v = net.ReadString();
table.insert( ClientUndos, 1, { Key = k, Name = v } )
MakeUIDirty()
end
usermessage.Hook( "AddUndo", AddUndo )
net.Receive( "Undo_AddUndo", AddUndo )
--[[---------------------------------------------------------
Expand All @@ -77,9 +77,9 @@ if ( CLIENT ) then
has been undone or made redundant. We act by updating
out data (We wait until the UI is viewed until updating)
-----------------------------------------------------------]]
local function Undone( message )
local function Undone( _ )
local key = message:ReadLong();
local key = net.ReadInt(16);
local NewUndo = {}
local i = 1
Expand All @@ -98,7 +98,7 @@ if ( CLIENT ) then
end
usermessage.Hook( "Undone", Undone )
net.Receive( "Undo_Undone", Undone )
--[[---------------------------------------------------------
MakeUIDirty
Expand Down Expand Up @@ -165,6 +165,9 @@ local PlayerUndo = {}
local Current_Undo = nil
util.AddNetworkString("Undo_Undone")
util.AddNetworkString("Undo_AddUndo")
--[[---------------------------------------------------------
GetTable
Returns the undo table for whatever reason
Expand Down Expand Up @@ -293,9 +296,9 @@ local function SendUndoneMessage( ent, id, ply )
-- For further optimization we could queue up the ids and send them
-- in one batch ever 0.5 seconds or something along those lines.
umsg.Start( "Undone", ply )
umsg.Long( id )
umsg.End()
net.Start( "Undo_Undone" )
net.WriteInt( id, 16 )
net.Send( ply )
end
Expand All @@ -315,10 +318,10 @@ function Finish( NiceText )
NiceText = NiceText or Current_Undo.Name
umsg.Start( "AddUndo", Current_Undo.Owner )
umsg.Long( id )
umsg.String( NiceText )
umsg.End()
net.Start( "Undo_AddUndo" )
net.WriteInt( id, 16 )
net.WriteString( NiceText )
net.Send( Current_Undo.Owner )
-- Have one of the entities in the undo tell us when it gets undone.
if ( Current_Undo.Entities[1] ) then
Expand Down Expand Up @@ -404,9 +407,9 @@ local function CC_UndoLast( pl, command, args )
local count = Do_Undo( last )
umsg.Start( "Undone", pl )
umsg.Long( lastk )
umsg.End()
net.Start( "Undo_Undone" )
net.WriteInt( lastk, 16 )
net.Send( pl )
PlayerUndo[ index ][ lastk ] = nil
Expand Down

0 comments on commit 228e317

Please sign in to comment.