README.md in joyce-0.1.2 vs README.md in joyce-0.1.3
- old
+ new
@@ -11,26 +11,23 @@
Joyce is a multiplayer game server framework built on top of Metacosm
## What is the big idea?
-The idea is to build 'isomorphic' Ruby games: to target both a Gosu game client as well as a game server
-running in the cloud. Both are running the same code, but the responsibilities are split:
+The idea is to build 'isomorphic' Ruby games: to target both a Gosu game client as well as a game server running in the cloud. Both are running the same code, but the responsibilities are split:
- The game server runs game business logic, and publishes events that the clients consume to hydrate their local views
- Clients publish commands the the server validates and handles, updating game state and generating events
-One upshot of this is that all game processing is kept on the server, and clients are doing nothing but
-rendering views and when necessary figuring out what commands to publish (when the user interacts).
+One upshot of this is that all game processing is kept on the server, and clients are doing nothing but rendering views and when necessary figuring out what commands to publish (when the user interacts).
## Features
## Examples
- Below is the source for a toy app that displays a list of other connected players and how long they've been connected. The server uses a ping command from clients to determine if players have disconnected.
+Below is the source for a toy app that displays a list of other connected players and how long they've been connected. The server uses a ping command from clients to determine if players have disconnected.
- ```ruby
require 'joyce'
module Example
class SampleAppView < Joyce::ApplicationView
def render
game_view.render(window, font)
@@ -41,25 +38,22 @@
end
end
class SampleServer < Joyce::Server
def setup
- # p [ :sample_server_setup ]
Game.create
end
def tick
- # p [ :sample_server_tick ]
Game.all.each(&:iterate!)
end
end
class Application < Joyce::Application
viewed_with Example::SampleAppView
def setup
- # p [ :sample_app_setup ]
GameView.create(active_player_id: player_id)
sim.params[:active_player_id] = player_id
end
def tick
@@ -142,43 +136,30 @@
end
end
private
def player_names
- self.player_views.map { |p| "#{p.name} (#{time_ago_in_words(p.joined_at)})" } #(&:name)
+ self.player_views.map { |p| "#{p.name} (#{time_ago_in_words(p.joined_at)})" }
end
end
class PingCommand < Metacosm::Command
attr_accessor :player_id, :player_name
end
class PingCommandHandler
def handle(player_id:, player_name:)
- p [ :ping, from_player: player_id ]
game = Game.find_by(players: { id: player_id })
if game.nil?
- # we could try to create a new game for the player?
- # or add them to an existing one?
- p [ :no_game_yet! ]
-
game = Game.first || Game.create
game.admit_player(player_id: player_id, player_name: player_name)
end
game.ping(player_id: player_id)
end
end
- #
- # class GameController
- # def ping(player_id:, player_name:)
- # game = Game.find_by ...
- # end
- # end
- #
-
class ApplicationEventListener < Metacosm::EventListener
def game_view
GameView.find_by(active_player_id: active_player_id)
end
@@ -191,14 +172,11 @@
attr_accessor :player_id, :player_name, :connected_player_list
end
class PlayerAdmittedEventListener < ApplicationEventListener
def receive(player_id:, player_name:, connected_player_list:)
- p [ :player_admitted_event_listener ]
if game_view
- # game_view.create_player_view(player_id: player_id, name: player_name, joined_at: Time.now)
- # go through connected player list and make views...
connected_player_list.each do |id:, name:, joined_at:|
player_view = game_view.player_views.where(player_id: id).first_or_create
player_view.update(name: name, joined_at: joined_at)
end
end
@@ -209,21 +187,19 @@
attr_accessor :player_id, :connected_player_list
end
class PlayerDroppedEventListener < ApplicationEventListener
def receive(player_id:, connected_player_list:)
- p [ :player_dropped_event_listener! ]
if game_view
game_view.player_views.map(&:destroy)
connected_player_list.each do |id:, name:, joined_at:|
player_view = game_view.player_views.where(player_id: id).first_or_create
player_view.update(name: name, joined_at: joined_at)
end
end
end
end
end
- ```
## Requirements
## Install