Class: WritersRoom::Commands::Actor

Inherits:
Thor
  • Object
show all
Defined in:
lib/writers_room/cli/actor.rb

Instance Method Summary collapse

Instance Method Details

#actor(character_file, scene_file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/writers_room/cli/actor.rb', line 16

def actor(character_file, scene_file)
  require_relative "../actor"

  unless File.exist?(character_file)
    say "Error: Character file not found: #{character_file}", :red
    exit 1
  end

  unless File.exist?(scene_file)
    say "Error: Scene file not found: #{scene_file}", :red
    exit 1
  end

  # Load character and scene info
  character_info = YAML.load_file(character_file)
  scene_info = YAML.load_file(scene_file)

  # Create and start the actor
  actor = WritersRoom::Actor.new(character_info)
  actor.set_scene(scene_info)

  say "#{actor.character_name} entering scene: #{scene_info[:scene_name]}", :green
  say "Listening on channel: #{options[:channel]}", :cyan
  say "Press Ctrl+C to exit", :yellow

  # Handle graceful shutdown
  trap("INT") do
    say "\n#{actor.character_name} exiting scene...", :yellow
    actor.stop
    exit 0
  end

  # Start performing
  actor.perform(channel: options[:channel])
rescue StandardError => e
  say "Error running actor: #{e.message}", :red
  say e.backtrace.join("\n"), :red if ENV["DEBUG"]
  exit 1
end