Sha256: 9e547b5332ab23358937674c83e4ad358c6255957248c4bc7704b71d65786de2

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# HACK Explicit requires to fix Opal's failure to resolve autoloads
require 'gamefic/query/expression'
require 'gamefic/query/matches'
require 'gamefic/grammar/verb_set'
require 'gamefic/plot/playbook'

# HACK Opal doesn't recognize classes and modules declared from scripts
def Object.const_missing sym
  Gamefic.const_get sym
end

module GameficOpal
  def self.static_plot
    @@static_plot ||= WebPlot.new(Gamefic::Source::Text.new)
  end
  def self.static_character
    if @@static_character.nil?
      @@static_character = static_plot.make Gamefic::Character, name: 'player', synonyms: 'me you myself yourself self'
      @@static_character.connect static_user
    end
    @@static_character
  end
  def self.static_user
    @@static_user ||= WebUser.new
  end
  class WebPlot < Gamefic::Plot
    def script path
      # Stub
    end
  end

  class WebUser < Gamefic::User::Base
    def save filename, data
      data[:metadata] = GameficOpal.static_plot.metadata
      `Gamefic.save(filename, data);`
    end
    def restore filename
      data = `Gamefic.restore(filename);`
      return data
    end
    def test_queue
      GameficOpal.static_character[:test_queue] || []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gamefic-sdk-1.5.0 lib/gamefic-sdk/platform/web/gamefic_opal.rb