Module: RuneRb::System::Setup

Extended by:
Setup
Included in:
Setup
Defined in:
app/system/setup.rb

Overview

Contains functions for setting up the <RuneRb::GLOBAL> hash.

Since:

  • 0.9.3

Instance Method Summary collapse

Instance Method Details

#init_game_data(settings) ⇒ Object

Create dataset objects related to game tables in the storage database.

Parameters:

  • settings (Hash)

    a collection mapping keys to dataset references.

Since:

  • 0.9.3


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/system/setup.rb', line 62

def init_game_data(settings)
  case settings[:STORAGE_TYPE]
  when :sqlite
    settings[:GAME_BANNED_NAMES] = settings[:CONNECTION][:game_banned_names]
    settings[:GAME_SNAPSHOTS] = settings[:CONNECTION][:game_snapshots]
  when :postgres
  else "Invalid storage mode! #{settings[:RRB_STORAGE_TYPE]}"
  end
rescue StandardError => e
  settings[:LOG].error 'An error occurred while loading game database!'
  settings[:LOG].error e
  settings[:LOG].error e.backtrace&.join("\n")
end

#init_global_data(settings) ⇒ Object

Populates the passed collection with settings read from the `asset/config/rune.rb.json` file. This function also attempts to initialize a connection to a storage database based on the information in `assets/config/rune.rb.json`.

Parameters:

  • settings (Hash)

    a collection mapping keys to global settings and a database connection.

Since:

  • 0.9.3


92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/system/setup.rb', line 92

def init_global_data(settings)
  Oj.load(File.read('assets/config/rune.rb.json')).each do |key, value|
    settings[key.upcase.to_sym] = value
  end
  settings[:STORAGE_TYPE] = settings[:STORAGE_TYPE].to_sym
  settings[:CONNECTION] = case settings[:STORAGE_TYPE]
                          when :sqlite
                            Sequel.sqlite('assets/sample.db3', pragma: :foreign_keys)
                          when :postgres
                          else Sequel.sqlite('assets/sample.db3')
                          end
  settings[:PROTOCOL] = settings[:PROTOCOL].to_sym
end

#init_item_data(settings) ⇒ Object

Create dataset objects related to item tables in the storage database.

Parameters:

  • settings (Hash)

    a collection mapping keys to dataset references.

Since:

  • 0.9.3


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/system/setup.rb', line 45

def init_item_data(settings)
  case settings[:STORAGE_TYPE]
  when :sqlite
    settings[:ITEM_SPAWNS] = settings[:CONNECTION][:item_spawns]
    settings[:ITEM_DEFINITIONS] = settings[:CONNECTION][:item_definitions]
    settings[:ITEM_EQUIPMENT] = settings[:CONNECTION][:item_equipment]
  when :postgres
  else "Invalid storage mode! #{settings[:RRB_STORAGE_TYPE]}"
  end
rescue StandardError => e
  settings[:LOG].error 'An error occurred while loading game database!'
  settings[:LOG].error e
  settings[:LOG].error e.backtrace&.join("\n")
end

#init_logger(settings) ⇒ Object

Constructs a global logger (with colors!).

Parameters:

  • settings (Hash)

    a collection mapping keys to logger settings.

Since:

  • 0.9.3


78
79
80
81
82
83
84
85
86
87
88
# File 'app/system/setup.rb', line 78

def init_logger(settings)
  settings[:VERSION] = `rake runerb:get_version`.chomp.gsub!('"', '')
  FileUtils.mkdir_p("#{FileUtils.pwd}/assets/log")
  settings[:LOG_FILE_PATH] = "#{FileUtils.pwd}/assets/log/rune_rb-#{Time.now.strftime('%Y-%m-%d').chomp}.log".freeze
  settings[:LOG_FILE] = Logger.new(settings[:LOG_FILE_PATH], progname: "rune.rb-#{settings[:VERSION]}")
  settings[:LOG] = Logger.new(STDOUT)
  settings[:COLOR] = Pastel.new
  settings[:LOG].formatter = proc do |sev, date, _prog, msg|
    "#{settings[:COLOR].green.bold("[#{date.strftime('%H:%M')}]")}|#{settings[:COLOR].blue("[#{sev}]")} : #{msg}\n"
  end
end

#init_mob_data(settings) ⇒ Object

Creates dataset objects related to mob tables in the storage database.

Parameters:

  • settings (Hash)

    a collection mapping keys to dataset references.

Since:

  • 0.9.3


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/system/setup.rb', line 7

def init_mob_data(settings)
  case settings[:STORAGE_TYPE]
  when :sqlite
    settings[:MOB_SPAWNS] = settings[:CONNECTION][:mob_spawns]
    settings[:MOB_STATS] = settings[:CONNECTION][:mob_stats]
    settings[:MOB_ANIMATIONS] = settings[:CONNECTION][:mob_animations]
    settings[:MOB_DEFINITIONS] = settings[:CONNECTION][:mob_definitions]
  when :postgres
  else "Invalid storage mode! #{settings[:RRB_STORAGE_TYPE]}"
  end
rescue StandardError => e
  settings[:LOG].error 'An error occurred while loading game database!'
  settings[:LOG].error e
  settings[:LOG].error e.backtrace&.join("\n")
end

#init_player_data(settings) ⇒ Object

Create dataset objects related to player tables in the storage database.

Parameters:

  • settings (Hash)

    a collection mapping keys to dataset references.

Since:

  • 0.9.3


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/system/setup.rb', line 25

def init_player_data(settings)
  case settings[:STORAGE_TYPE]
  when :sqlite
    settings[:PLAYER_APPEARANCES] = settings[:CONNECTION][:player_appearance]
    settings[:PLAYER_PROFILES] = settings[:CONNECTION][:player_profiles]
    settings[:PLAYER_LOCATIONS] = settings[:CONNECTION][:player_locations]
    settings[:PLAYER_SETTINGS] = settings[:CONNECTION][:player_settings]
    settings[:PLAYER_STATS] = settings[:CONNECTION][:player_stats]
    settings[:PLAYER_STATUS] = settings[:CONNECTION][:player_status]
  when :postgres
  else "Invalid storage mode! #{settings[:RRB_STORAGE_TYPE]}"
  end
rescue StandardError => e
  settings[:LOG].error 'An error occurred while loading game database!'
  settings[:LOG].error e
  settings[:LOG].error e.backtrace&.join("\n")
end