Skip to content

Commit

Permalink
Add Marker Events
Browse files Browse the repository at this point in the history
  • Loading branch information
Dahlgren committed Oct 26, 2019
1 parent 6243f53 commit 2e7acaf
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def create_event(params)
def event_params(params)
params.require(:event).permit(
:timestamp,
marker: [:id, :alpha, :brush, :color, :shape, :text, :type, position: [:dir, :x, :y, :z], size: [:height, :width]],
player: [:name, :uid],
projectile: [:id, :side, :simulation, position: [:dir, :x, :y, :z]],
unit: [:id, :life_state, :name, :side, :vehicle_id, position: [:dir, :x, :y, :z]],
Expand Down
5 changes: 5 additions & 0 deletions app/models/events/marker_created.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Events::MarkerCreated < Event
embeds_one :marker, class_name: 'Schemas::Marker'

validates_presence_of :marker
end
5 changes: 5 additions & 0 deletions app/models/events/marker_deleted.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Events::MarkerDeleted < Event
embeds_one :marker, class_name: 'Schemas::Marker'

validates_presence_of :marker
end
5 changes: 5 additions & 0 deletions app/models/events/marker_position.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Events::MarkerPosition < Event
embeds_one :marker, class_name: 'Schemas::Marker'

validates_presence_of :marker
end
15 changes: 15 additions & 0 deletions app/models/schemas/marker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Schemas::Marker
include ArDocStore::EmbeddableModel

json_attribute :id, as: :string
json_attribute :alpha, as: :string
json_attribute :brush, as: :string
json_attribute :color, as: :string
embeds_one :position, class_name: 'Schemas::Position'
json_attribute :shape, as: :string
embeds_one :size, class_name: 'Schemas::MarkerSize'
json_attribute :text, as: :string
json_attribute :type, as: :string

validates_presence_of :id, :alpha, :brush, :color, :position, :shape, :size, :text, :type
end
8 changes: 8 additions & 0 deletions app/models/schemas/marker_size.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Schemas::MarkerSize
include ArDocStore::EmbeddableModel

json_attribute :height, as: :float
json_attribute :width, as: :float

validates_presence_of :height, :width
end
3 changes: 3 additions & 0 deletions app/serializers/events/marker_created_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Events::MarkerCreatedSerializer < EventSerializer
has_one :marker
end
3 changes: 3 additions & 0 deletions app/serializers/events/marker_deleted_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Events::MarkerDeletedSerializer < EventSerializer
has_one :marker
end
3 changes: 3 additions & 0 deletions app/serializers/events/marker_position_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Events::MarkerPositionSerializer < EventSerializer
has_one :marker
end

0 comments on commit 2e7acaf

Please sign in to comment.