Module: Drakkon::Init

Defined in:
lib/drakkon/init.rb

Overview

Run Command for CLI

Class Method Summary collapse

Class Method Details

.directoriesObject



70
71
72
73
74
75
76
77
78
# File 'lib/drakkon/init.rb', line 70

def self.directories
  LogBot.info('Init', 'Directories Setup')

  ['app', 'fonts', 'metadata', 'fonts', 'sounds', 'sprites', 'app/drakkon'].each do |dir|
    next if Dir.exist?(dir)

    Dir.mkdir dir
  end
end

.go!(_raw = nil) ⇒ Object

General Run



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/drakkon/init.rb', line 5

def self.go!(_raw = nil)
  if Settings.init?
    LogBot.info('Init', 'Already Configured!')
    exit(0)
  end

  run!
rescue SystemExit, Interrupt
  LogBot.info('Init', 'Exiting')
  exit
end

.main_tickObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/drakkon/init.rb', line 80

def self.main_tick
  <<~MAIN
    require 'app/drakkon/bundle.rb'

    def tick(gtk_args)
      # args.gtk.slowmo! 2
      # =========================================================
    end
  MAIN
end

.metadataObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/drakkon/init.rb', line 44

def self.
  # Icon is required for build
  try_write('metadata/icon.png') do |to|
    FileUtils.cp(metdata_dir('icon.png'), to)
  end

  # Copy metdata files
  try_write('metadata/game_metadata.txt') do |to|
    FileUtils.cp(metdata_dir('game_metadata.txt'), to)
  end
end

.metdata_dir(file_name = nil) ⇒ Object



56
57
58
# File 'lib/drakkon/init.rb', line 56

def self.metdata_dir(file_name = nil)
  "#{Run.version_dir}/mygame/metadata/#{file_name}"
end

.promptObject



91
92
93
# File 'lib/drakkon/init.rb', line 91

def self.prompt
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
end

.run!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/drakkon/init.rb', line 17

def self.run!
  unless Hub.version_installed?
    LogBot.warn('Init', 'No Drakkon Versions Installed, Run `drakkon install <dragonruby.zip>` first!')
    exit(1)
  end

  exit if prompt.no?("Init Drakkon here? #{Dir.pwd.pastel(:yellow)}")
  LogBot.info('Init', 'Start')
  settings
  directories
  

  # TODO: Validate / Confirm
  try_write('app/main.rb') do |to|
    File.write(to, main_tick)
  end
end

.settingsObject



60
61
62
63
64
65
66
67
68
# File 'lib/drakkon/init.rb', line 60

def self.settings
  LogBot.info('Init', 'Settings Setup')

  # If we're here, it means Settings.init? returned false,
  # which eans the config file doesn't exist.
  # As a happy accident, accessing Settings.config for the first time also
  # writes out a default config file
  Settings.config
end

.try_write(to, &blk) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/drakkon/init.rb', line 35

def self.try_write(to, &blk)
  if File.exist?(to)
    LogBot.warn('Init', "- Tried to create #{to} but it already exists")
  else
    LogBot.info('Init', "- Created #{to}")
    blk.call(to)
  end
end