Class: ItchWizard

Inherits:
Object show all
Includes:
Metadata
Defined in:
dragon/itch_wizard.rb

Overview

Copyright 2019 DragonRuby LLC MIT License itch_wizard.rb has been released under MIT (*only this file*).

Instance Method Summary collapse

Methods included from Metadata

#get_metadata, #metadata_file_path, #write_blank_metadata

Constructor Details

#initializeItchWizard

Returns a new instance of ItchWizard.


213
214
215
# File 'dragon/itch_wizard.rb', line 213

def initialize
  reset
end

Instance Method Details

#check_metadataObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'dragon/itch_wizard.rb', line 15

def 
   = $gtk.read_file 
  if !
    
  end

  if .each_line.to_a.length != 6
    
  end

  log "* INFO: Contents of #{}:"
  log "#+begin_src txt"
  .each_line { |l| log "  #{l}" }
  log "#+end_src"
   = 

  if [:dev_id].start_with?("#") || !@dev_id
    log "* PROMPT: Please provide your username for Itch."
    $console.set_command "$wizards.itch.set_dev_id \"your-itch-username\""
    return :need_dev_id
  end

  if [:dev_title].start_with?("#") || !@dev_title
    log "* PROMPT: Please provide developer's/company's name that you want displayed."
    $console.set_command "$wizards.itch.set_dev_title \"Your Name\""
    return :need_dev_title
  end

  if [:game_id].start_with?("#") || !@game_id
    log "* PROMPT: Please provide the id for you game. This is the id you specified when you set up a new game page on Itch."
    $console.set_command "$wizards.itch.set_game_id \"your-game-id\""
    return :need_game_id
  end

  if [:game_title].start_with?("#") || !@game_title
    log "* PROMPT: Please provide the display name for your game. (This can include spaces)"
    $console.set_command "$wizards.itch.set_game_title \"Your Game\""
    return :need_game_title
  end

  if [:version].start_with?("#") || !@version
    log "* PROMPT: Please provide the version for your game."
    $console.set_command "$wizards.itch.set_version \"1.0\""
    return :need_version
  end

  if [:icon].start_with?("#") || !@icon
    log "* PROMPT: Please provide icon path for your game."
    $console.set_command "$wizards.itch.set_icon \"icon.png\""
    return :need_icon
  end

  return :success
end

#deployObject


155
156
157
158
159
160
161
162
# File 'dragon/itch_wizard.rb', line 155

def deploy
  log_info "* Running dragonruby-publish: #{package_command}"
  results = $gtk.exec package_command
  log "#+begin_src"
  log results
  log "#+end_src"
  :success
end

#init_wizard_statusObject


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'dragon/itch_wizard.rb', line 217

def init_wizard_status
  @wizard_status = {}

  steps.each do |m|
    @wizard_status[m] = { result: :not_started }
  end

  previous_step = nil
  next_step = nil

  steps.each_cons(2) do |current_step, next_step|
    @wizard_status[current_step][:next_step] = next_step
  end

  steps.reverse.each_cons(2) do |current_step, previous_step|
    @wizard_status[current_step][:previous_step] = previous_step
  end
end

#package_commandObject


151
152
153
# File 'dragon/itch_wizard.rb', line 151

def package_command
  "#{File.join $gtk.get_base_dir, 'dragonruby-publish'}"
end

#relative_pathObject


147
148
149
# File 'dragon/itch_wizard.rb', line 147

def relative_path
  (File.dirname $gtk.binary_path)
end

#resetObject


198
199
200
201
202
203
204
205
206
# File 'dragon/itch_wizard.rb', line 198

def reset
  @dev_id = nil
  @dev_title = nil
  @game_id = nil
  @game_title = nil
  @version = nil
  @icon = nil
  init_wizard_status
end

#restartObject


208
209
210
211
# File 'dragon/itch_wizard.rb', line 208

def restart
  reset
  start
end

#set_dev_id(value) ⇒ Object


70
71
72
73
74
# File 'dragon/itch_wizard.rb', line 70

def set_dev_id value
  @dev_id = value
  
  start
end

#set_dev_title(value) ⇒ Object


76
77
78
79
80
# File 'dragon/itch_wizard.rb', line 76

def set_dev_title value
  @dev_title = value
  
  start
end

#set_game_id(value) ⇒ Object


82
83
84
85
86
# File 'dragon/itch_wizard.rb', line 82

def set_game_id value
  @game_id = value
  
  start
end

#set_game_title(value) ⇒ Object


88
89
90
91
92
# File 'dragon/itch_wizard.rb', line 88

def set_game_title value
  @game_title = value
  
  start
end

#set_icon(value) ⇒ Object


100
101
102
103
104
# File 'dragon/itch_wizard.rb', line 100

def set_icon value
  @icon = value
  
  start
end

#set_version(value) ⇒ Object


94
95
96
97
98
# File 'dragon/itch_wizard.rb', line 94

def set_version value
  @version = value
  
  start
end

#startObject


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'dragon/itch_wizard.rb', line 164

def start
  log "================"
  log "* INFO: Starting Itch Wizard."
  @start_at = Kernel.global_tick_count
  steps.each do |m|
    begin
      log_info "Running Itch Wizard Step: ~$wizards.itch.#{m}~"
      result = (send m) || :success if @wizard_status[m][:result] != :success
      @wizard_status[m][:result] = result
      if result != :success
        log_info "Exiting wizard. :#{result}"
        break
      end
    rescue Exception => e
      if e.is_a? WizardException
        $console.log.clear
        $console.archived_log.clear
        log "=" * $console.console_text_width
        e.console_primitives.each do |p|
          $console.add_primitive p
        end
        log "=" * $console.console_text_width
        $console.set_command (e.console_command || "$wizards.itch.start")
      else
        log_error "Step #{m} failed."
        log_error e.to_s
        $console.set_command "$wizards.itch.start"
      end

      break
    end
  end
end

#stepsObject


8
9
10
11
12
13
# File 'dragon/itch_wizard.rb', line 8

def steps
  [
    :check_metadata,
    :deploy
  ]
end

#write_metadataObject


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'dragon/itch_wizard.rb', line 106

def 
  text = ""
  if @dev_id
    text += "devid=#{@dev_id}\n"
  else
    text += "#devid=myname\n"
  end

  if @dev_title
    text += "devtitle=#{@dev_title}\n"
  else
    text += "#devtitle=My Name\n"
  end

  if @game_id
    text += "gameid=#{@game_id}\n"
  else
    text += "#gameid=gameid\n"
  end

  if @game_title
    text += "gametitle=#{@game_title}\n"
  else
    text += "#gametitle=Game Name\n"
  end

  if @version
    text += "version=#{@version}\n"
  else
    text += "#version=0.1\n"
  end

  if @icon
    text += "icon=metadata/#{@icon}\n"
  else
    text += "#icon=metadata/icon.png\n"
  end

  $gtk.write_file , text
end