mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
feat: Add standalone mode support
- Create DemoUser migration for standalone development - Add DemoUser model with polymorphic games association - Add configuration system (standalone vs mounted) - Use ENV variables for configuration - current_player method supports both modes (ApplicationController) - Can run without Hacktivity for development
This commit is contained in:
18
app/models/break_escape/demo_user.rb
Normal file
18
app/models/break_escape/demo_user.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module BreakEscape
|
||||
class DemoUser < ApplicationRecord
|
||||
self.table_name = 'break_escape_demo_users'
|
||||
|
||||
has_many :games, as: :player, class_name: 'BreakEscape::Game'
|
||||
|
||||
validates :handle, presence: true, uniqueness: true
|
||||
|
||||
# Mimic User role methods
|
||||
def admin?
|
||||
role == 'admin'
|
||||
end
|
||||
|
||||
def account_manager?
|
||||
role == 'account_manager'
|
||||
end
|
||||
end
|
||||
end
|
||||
9
config/initializers/break_escape.rb
Normal file
9
config/initializers/break_escape.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# BreakEscape Engine Configuration
|
||||
BreakEscape.configure do |config|
|
||||
# Set to true for standalone mode (development)
|
||||
# Set to false when mounted in Hacktivity (production)
|
||||
config.standalone_mode = ENV['BREAK_ESCAPE_STANDALONE'] == 'true'
|
||||
|
||||
# Demo user handle for standalone mode
|
||||
config.demo_user_handle = ENV['BREAK_ESCAPE_DEMO_USER'] || 'demo_player'
|
||||
end
|
||||
12
db/migrate/20251120160000_create_break_escape_demo_users.rb
Normal file
12
db/migrate/20251120160000_create_break_escape_demo_users.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateBreakEscapeDemoUsers < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :break_escape_demo_users do |t|
|
||||
t.string :handle, null: false
|
||||
t.string :role, default: 'user', null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :break_escape_demo_users, :handle, unique: true
|
||||
end
|
||||
end
|
||||
@@ -2,5 +2,28 @@ require "break_escape/version"
|
||||
require "break_escape/engine"
|
||||
|
||||
module BreakEscape
|
||||
# Your code goes here...
|
||||
class << self
|
||||
attr_accessor :configuration
|
||||
end
|
||||
|
||||
def self.configure
|
||||
self.configuration ||= Configuration.new
|
||||
yield(configuration) if block_given?
|
||||
end
|
||||
|
||||
def self.standalone_mode?
|
||||
configuration&.standalone_mode || false
|
||||
end
|
||||
|
||||
class Configuration
|
||||
attr_accessor :standalone_mode, :demo_user_handle
|
||||
|
||||
def initialize
|
||||
@standalone_mode = false
|
||||
@demo_user_handle = 'demo_player'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Initialize with defaults
|
||||
BreakEscape.configure {}
|
||||
|
||||
Reference in New Issue
Block a user