Class: Tester

Inherits:
Object show all
Defined in:
scripts/00700 Ajout_PSDK/00200 Tester.rb

Overview

Class designed to test an interface or a script

Constant Summary collapse

@@args =
nil
@@class =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script) ⇒ Tester

Create a new test

Parameters:

  • script (String)

    filename of the script to test



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 9

def initialize(script)
  @script = script
  $tester = self
  Object.define_method(:reload) { $tester.load_script }
  Object.define_method(:restart) { $tester.restart_scene }
  Object.define_method(:quit) { $tester.quit_test }
  data_load
  PFM::GameState.new.expand_global_var
  @thread = Thread.new do 
    while true
      sleep(0.1)
      if Input::Keyboard.press?(Input::Keyboard::F9)
        print "\rMouse coords = %d,%d\nCommande : " % [Mouse.x, Mouse.y]
        sleep(0.5)
      end
    end
  end
  load_script
  show_test_message
  @unlocked = true
rescue Exception
  manage_exception
end

Class Method Details

.start(klass, *args)

Define the class and the arguments of it to test

Parameters:

  • klass (Class)

    the class to test

  • args (Array)

    the arguments



88
89
90
91
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 88

def self.start(klass, *args)
  @@class = klass
  @@args = args
end

Instance Method Details

#data_load

Load the RMXP Data



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 93

def data_load
  unless $data_actors
    $data_actors        = _clean_name_utf8(load_data("Data/Actors.rxdata"))
    $data_classes       = _clean_name_utf8(load_data("Data/Classes.rxdata"))
    $data_enemies       = _clean_name_utf8(load_data("Data/Enemies.rxdata"))
    $data_troops        = _clean_name_utf8(load_data("Data/Troops.rxdata"))
    $data_tilesets      = _clean_name_utf8(load_data("Data/Tilesets.rxdata"))
    $data_common_events = _clean_name_utf8(load_data("Data/CommonEvents.rxdata"))
    $data_system        = load_data_utf8("Data/System.rxdata")
  end
  $game_system = Game_System.new
  $game_temp = Game_Temp.new
end

#load_scripttrue

Load the script

Returns:

  • (true)


70
71
72
73
74
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 70

def load_script
  script = File.open(@script, "r") { |f| break(f.read(f.size)) }
  eval(script, $global_binding, @script)
  return true
end

#main

Main process of the tester



33
34
35
36
37
38
39
40
41
42
43
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 33

def main
  Graphics.update until @unlocked
  $scene = @@class.new(*@@args)
  $scene.main
  if $scene != self
    $scene = nil
    @thread.kill
  end
rescue Exception
  manage_exception
end

#manage_exception

Manage the exception



76
77
78
79
80
81
82
83
84
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 76

def manage_exception
  raise if $!.class == LiteRGSS::DisplayWindow::ClosedWindowError
  puts Yuki::EXC.build_error_log($!)
  cc 0x01
  puts "Test locked, type reload and restart to unlock"
  cc 0x07
  restart_scene
  @unlocked = false
end

#quit_test

Quit the test



64
65
66
67
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 64

def quit_test
  restart_scene
  $scene = nil
end

#restart_scenetrue

Retart the scene

Returns:

  • (true)


46
47
48
49
50
51
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 46

def restart_scene
  $scene.instance_variable_set(:@running, false)
  $scene = self
  @unlocked = true
  return true
end

#show_test_message

Show the test message



53
54
55
56
57
58
59
60
61
62
# File 'scripts/00700 Ajout_PSDK/00200 Tester.rb', line 53

def show_test_message
  cc 0x02
  puts "Testing script #{@script}"
  cc 0x07
  puts "Type : "
  puts "reload to reload the script"
  puts "restart to restart the scene"
  puts "quit to quit the test"
  print "Commande : "
end