-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hey! Thanks for creating Scale! It's been helpful on my first DR game.
One thing that didn't please me was how all the game Scenes had to live inside the same scope. I understand how handy is being able to use Scene.send(:"tick_#{args.state.scene}", args), but the way the template is set encourages people to put all the scene behavior as methods under Scene. That can cause methods from one scene leaking (or worse, overriding) other scenes! For instance:
# scenes/gameplay.rb
module Scene
def self.tick_gameplay(args)
update(args)
end
def update(args)
end
end
# scenes/pause.rb
module Scene
def self.tick_pause(args)
update(args)
end
# this will override the update method in the gameplay scene
def update(args)
end
endI propose a gentle change (so we can still use send as before), but that namespaces the specifics of each scene. Each scene is still defined in a separate file, with a corresponding tick_#{scene} method. But that method will use an inner module to define its behavior:
# scenes/gameplay.rb
module Scene
def self.tick_gameplay(args)
GameplayScene.tick(args)
end
module GameplayScene
class << self
def tick(args)
# do stuff
end
private
# you can define private helper methods that don't pollute the Scene namespace
end
end
end
# scenes/pause.rb
module Scene
def self.tick_pause(args)
PauseScene.tick(args)
end
module PauseScene
class << self
def tick(args)
# do pause stuff
end
private
# pause helper methods
end
end
endThis won't vastly change the template, but it promotes better defaults, IMO. Thoughts?