mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
- Move scenarios from app/assets/scenarios/ to scenarios/ - Update Mission model to use BreakEscape::Engine.root instead of Rails.root - Update seeds.rb to use engine root for scenario discovery - Update tests to use engine root for path assertions This ensures scenarios are found correctly in both mounted (Hacktivity) and standalone (test) environments. All 12 tests now passing with 19 assertions!
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
module BreakEscape
|
|
class Mission < ApplicationRecord
|
|
self.table_name = 'break_escape_missions'
|
|
|
|
has_many :games, class_name: 'BreakEscape::Game', dependent: :destroy
|
|
|
|
validates :name, presence: true, uniqueness: true
|
|
validates :display_name, presence: true
|
|
validates :difficulty_level, inclusion: { in: 1..5 }
|
|
|
|
scope :published, -> { where(published: true) }
|
|
|
|
# Path to scenario directory
|
|
def scenario_path
|
|
BreakEscape::Engine.root.join('scenarios', name)
|
|
end
|
|
|
|
# Generate scenario data via ERB
|
|
def generate_scenario_data
|
|
template_path = scenario_path.join('scenario.json.erb')
|
|
raise "Scenario template not found: #{name}" unless File.exist?(template_path)
|
|
|
|
erb = ERB.new(File.read(template_path))
|
|
binding_context = ScenarioBinding.new
|
|
output = erb.result(binding_context.get_binding)
|
|
|
|
JSON.parse(output)
|
|
rescue JSON::ParserError => e
|
|
raise "Invalid JSON in #{name} after ERB processing: #{e.message}"
|
|
end
|
|
|
|
# Binding context for ERB variables
|
|
class ScenarioBinding
|
|
def initialize
|
|
@random_password = SecureRandom.alphanumeric(8)
|
|
@random_pin = rand(1000..9999).to_s
|
|
@random_code = SecureRandom.hex(4)
|
|
end
|
|
|
|
attr_reader :random_password, :random_pin, :random_code
|
|
|
|
def get_binding
|
|
binding
|
|
end
|
|
end
|
|
end
|
|
end
|