From 844a57be52a2e243832e3d83d148fa3cea6d5ad1 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Tue, 5 Mar 2013 01:56:13 +0100 Subject: [PATCH] Avoid repeating serialization codes. --- NJOutputKeyPress.m | 4 +++- NJOutputMapping.m | 2 +- NJOutputMouseButton.m | 2 +- NJOutputMouseMove.m | 2 +- NJOutputMouseScroll.m | 2 +- NJOutputSwitchMouseMode.m | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/NJOutputKeyPress.m b/NJOutputKeyPress.m index 5371475..622cf41 100644 --- a/NJOutputKeyPress.m +++ b/NJOutputKeyPress.m @@ -16,7 +16,9 @@ } - (NSDictionary *)serialize { - return @{ @"type": @"key press", @"key": @(_vk) }; + return _vk != NJKeyInputFieldEmpty + ? @{ @"type": self.class.serializationCode, @"key": @(_vk) } + : nil; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization diff --git a/NJOutputMapping.m b/NJOutputMapping.m index 5cd5d9f..6c1ba95 100644 --- a/NJOutputMapping.m +++ b/NJOutputMapping.m @@ -19,7 +19,7 @@ - (NSDictionary *)serialize { return _mapping - ? @{ @"type": @"mapping", @"name": _mapping.name } + ? @{ @"type": self.class.serializationCode, @"name": _mapping.name } : nil; } diff --git a/NJOutputMouseButton.m b/NJOutputMouseButton.m index 0cc403f..ad44b39 100644 --- a/NJOutputMouseButton.m +++ b/NJOutputMouseButton.m @@ -14,7 +14,7 @@ } - (NSDictionary *)serialize { - return @{ @"type": @"mouse button", @"button": @(_button) }; + return @{ @"type": self.class.serializationCode, @"button": @(_button) }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization diff --git a/NJOutputMouseMove.m b/NJOutputMouseMove.m index 3346fb2..8efb8cb 100644 --- a/NJOutputMouseMove.m +++ b/NJOutputMouseMove.m @@ -22,7 +22,7 @@ } - (NSDictionary *)serialize { - return @{ @"type": @"mouse move", @"axis": @(_axis) }; + return @{ @"type": self.class.serializationCode, @"axis": @(_axis) }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization diff --git a/NJOutputMouseScroll.m b/NJOutputMouseScroll.m index 2f6d2d6..4aa614d 100644 --- a/NJOutputMouseScroll.m +++ b/NJOutputMouseScroll.m @@ -16,7 +16,7 @@ } - (NSDictionary *)serialize { - return @{ @"type": @"mouse scroll", @"amount": @(_amount) }; + return @{ @"type": self.class.serializationCode, @"amount": @(_amount) }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization diff --git a/NJOutputSwitchMouseMode.m b/NJOutputSwitchMouseMode.m index 1750869..130a2a0 100644 --- a/NJOutputSwitchMouseMode.m +++ b/NJOutputSwitchMouseMode.m @@ -17,7 +17,7 @@ } - (NSDictionary *)serialize { - return @{ @"type": @"switch mouse mode" }; + return @{ @"type": self.class.serializationCode }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization -- 2.30.2