This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
configure.rb
89 lines (80 loc) · 3.05 KB
/
configure.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
require "digest"
require "json"
require "tty-prompt"
require_relative "console"
class PSExo
def configure
prompt = TTY::Prompt.new
exos = Dir.glob(__dir__ + "/exos/*.exo")
answers = {
background: "",
jacket: "",
assets: "",
movie: "",
data: File.expand_path("./dist/#{@chart_id}/data.ped").gsub("/", "\\\\\\\\"),
ap: true,
scale: 1,
}
CPuts.info "ファイルの設定を行います。パスを入力して下さい。"
CPuts.warn "パスの両端の\"は取り除かれます。"
answers[:background] = prompt.ask("背景ファイル(省略で自動生成):") || download_background
answers[:jacket] = prompt.ask("ジャケット(省略でダウンロード):") || download_jacket
answers[:assets] = prompt.ask("assetsフォルダ(省略でこのフォルダのassets):") || File.expand_path("./assets")
answers[:movie] = prompt.ask("プレイ動画(省略可能):") do |q|
q.validate ->(value) { value.empty? || File.exist?(process_path(value)) }, "プレイ動画が見付かりません。"
q.default ""
end
answers[:ap] = prompt.yes?("AP時のコンボ表示にしますか?").to_s
answers[:scale] = calc_scale(answers[:jacket]).to_s
exos.each do |exo|
contents = File.read(exo, encoding: Encoding::SJIS).encode(Encoding::UTF_8)
answers.each do |key, value|
contents.gsub!("!!#{key}!!", process_path(value))
end
File.write("./dist/#{@chart_id}/" + File.basename(exo), contents, encoding: Encoding::SJIS, errors: :replace)
end
content = File.read("./dist/#{@chart_id}/data.tmp.ped")
answers.each do |key, value|
content.gsub!("!!#{key}!!", process_path(value))
end
CPuts.success "ファイルの設定が完了しました。"
File.write("./dist/#{@chart_id}/data.ped", content)
end
def process_path(value)
value
.gsub("/", "\\")
.gsub("\\", "\\\\\\\\")
.gsub(/^"|"$/, "")
.gsub(/\\$/, "")
.encode(Encoding::UTF_8)
end
def download_background
print "\e[90m背景画像をダウンロードしています...\e[m"
data = JSON.parse(
http_get("https://fp.sevenc7c.com/sonolus/levels/frpt-#{@chart_id}").body,
symbolize_names: true,
)
File.write(
"./dist/#{@chart_id}/background.png",
http_get("https://fp.sevenc7c.com" + data[:item][:useBackground][:item][:image][:url]).body.to_s,
mode: "wb",
)
puts "\e[92m 完了\e[m"
File.expand_path("./dist/#{@chart_id}/background.png")
end
def download_jacket
print "\e[90mジャケットをダウンロードしています...\e[m"
data = JSON.parse(
http_get("https://servers.purplepalette.net/sonolus/levels/#{@chart_id}").body,
symbolize_names: true,
)
File.write(
"./dist/#{@chart_id}/jacket.png",
http_get("https://servers.purplepalette.net" + data[:item][:cover][:url]).body.to_s,
mode: "wb",
)
puts "\e[92m 完了\e[m"
File.expand_path("./dist/#{@chart_id}/jacket.png")
end
end