Class: Setup

Inherits:
AkaneSound show all
Defined in:
lib/akane_sound/class.setup.rb

Class Method Summary collapse

Methods inherited from AkaneSound

#initialize, #run, #set_status

Constructor Details

This class inherits a constructor from AkaneSound

Class Method Details

.init(arg) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/akane_sound/class.setup.rb', line 2

def self.init(arg)
  @@pref_dir = SDL2.preference_path("ruby_app", "akane_sound")
  if arg == "debug"
    @@debug_flag = true
    File.delete(File.open(@@pref_dir+'config.yaml')) if File.exist?(@@pref_dir+'config.yaml')
    #File.delete(File.open(@@pref_dir+'save_data.yaml'))
  end
  str = (@@debug_flag) ? "cache_debug.yaml" : "cache.yaml"
  if File.exist?(File.join(@@pref_dir, str))
    @@cache = YAML.load(File.open(File.join(@@pref_dir, str)))
  end
  Setup::prepare_config
  Setup::prepare_save_data
  #Setup::prepare_binary_data('akane_bg.png')
  #Setup::prepare_binary_data('NotoSansCJKjp-Regular.otf')
  #Setup::prepare_binary_data('NotoSansCJKjp-Medium.otf')
  #Setup::prepare_binary_data('NotoSansCJKjp-Bold.otf')
end

.prepare_binary_data(filename) ⇒ Object



58
59
60
61
62
# File 'lib/akane_sound/class.setup.rb', line 58

def self.prepare_binary_data(filename)
  unless File.file?(@@pref_dir+filename)
    Util.binary_copy(@@pref_dir, filename)
  end
end

.prepare_configObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/akane_sound/class.setup.rb', line 21

def self.prepare_config
  unless File.file?(@@pref_dir+"config.yaml")
    file = File.open(File.join(__dir__, "../../data/config.yaml"), "r")
    contents = file.read
    file.close
    #contents.sub! 'FILE_PATH_BG', @@pref_dir+'akane_bg.png'
    contents.sub!('FILE_PATH_BACKGROUND',
                File.join(__dir__, '../../data/akane_bg.png'))
    contents.sub!('FILE_PATH_FONT_BOLD',
                File.join(__dir__, '../../data/NotoSansCJKjp-Bold.otf'))
    contents.sub!('FILE_PATH_FONT',
                File.join(__dir__, '../../data/NotoSansCJKjp-Regular.otf'))
    contents.sub!('FILE_PATH_ROOT', Dir.home)

    File.open(@@pref_dir+'config.yaml', 'w') { |file| file.write(contents) }
    @@config = YAML.load(File.open(@@pref_dir+'config.yaml'))
  else
    @@config = YAML.load(File.open(@@pref_dir+'config.yaml'))
  end
  @@config[:root_dir] += '/' unless @@config[:root_dir][-1] == '/'
end

.prepare_save_dataObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/akane_sound/class.setup.rb', line 43

def self.prepare_save_data
  unless File.file?(@@pref_dir+"save_data.yaml")
    file = File.open(File.join(__dir__, "../../data/save_data.yaml"), "r")
    contents = file.read
    file.close

    File.open(@@pref_dir+'save_data.yaml', 'w') do |file|
      file.write(contents)
    end
    @@save_data = YAML.load(File.open(@@pref_dir+'save_data.yaml'))
  else
    @@save_data = YAML.load(File.open(@@pref_dir+'save_data.yaml'))
  end
end