jp_quest 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35e9ce08dc713c11e7972f330006d8af55906971876cad0d5747a20231734b41
4
- data.tar.gz: cb2f5ff1a82825de5d6710783d24b66543ceaa83a0430cef85b603d1cd71e795
3
+ metadata.gz: bacad61b26638c3d1bd038a0da019946218db0cd4008b99cd24107ff2838aa84
4
+ data.tar.gz: 98d0c0c49ee3d1d18dcee40e0f747f3866239af824cb25faf285b8f601eb70c6
5
5
  SHA512:
6
- metadata.gz: 6b2d660043bf3c6066784cf78f420396ee65652bf898135208520f8d85a45e277cf1f049c5ebb3d18385310722ac59d901a0e2e5f8a20dcefdefa96fe4c18702
7
- data.tar.gz: 8520014fd3d5c4ac62c372613e2f0e7038b149770e8c8ddcc18f1109b97777ec2f756e4388926922d6eb80321520d1be3813edb417f4a0aefe24e226d7a426f8
6
+ metadata.gz: a318a51f4ca3feee083b749aa96cd53eeb3761f5bcd2c3d68e259e4c79a12e996a653dcb36688cb45ce5d88b2f3f8adbc17c21c1e3c292b758fbf6149f3e7ee7
7
+ data.tar.gz: 0635bcd6aff4e1958b833d31a8f7ba9cc153349450fd2e8336014767c99e8f113d906a3738b927e79898bc1d8c622778f99bde58d64a729c4320d90bae05b603
data/CHANGELOG.md CHANGED
@@ -14,4 +14,9 @@
14
14
 
15
15
  ## [0.1.3] - 2024-10/8
16
16
 
17
- - バグ修正
17
+ - バグ修正
18
+
19
+ ## [0.2.0] - 2024-10/9
20
+
21
+ - 出力時のダブルクオート数、インデント数が崩れていたのを出来るだけ抑制
22
+ - quests.snbtのパス名も変換されていたのを修正
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## JpQuest
2
2
 
3
- Translator for `.snbt` files. (title, subtitle, description)
3
+ Translator for FTBQuest. (title, subtitle, description)
4
4
  If you want to translate to other languages than Japanese,
5
5
  please add the `exchange_language` option during initialization.
6
6
  Can always get help with `JpQuest.help`
@@ -15,7 +15,7 @@ Can always get help with `JpQuest.help`
15
15
  2. Make `.env` file
16
16
  3. Add `OPENAI_API_KEY=your_api_key` to `.env`
17
17
  4. Optional: Add `OPENAI_MODEL=some_openai_model` to `.env` **(default: gpt-4o-mini)**
18
- 5. Add `some.snbt` to `quests` directory
18
+ 5. Add `some.snbt` or `quests` directory contents to `quests` directory
19
19
  6. Check `output` directory
20
20
 
21
21
  ## Initialize Options
@@ -38,4 +38,4 @@ Which language do you want to translate to?
38
38
  #### display_help
39
39
 
40
40
  Want to display help?
41
- **(default: true)**
41
+ **(default: true)**
data/dist/example.rb CHANGED
@@ -5,4 +5,4 @@ performer = JpQuest::Performer.new
5
5
  # file_path = "some.snbt"
6
6
  # performer.perform(file_path)
7
7
 
8
- performer.perform_directory
8
+ performer.perform_directory(dir_path: "dist/quests")
@@ -11,53 +11,70 @@ module JpQuest
11
11
  # @param [String] indent インデント
12
12
  # @return [String] SNBT形式に整形したコンテンツ
13
13
  def format_overwritable_lines(content, indent)
14
- mid_indent = middle_indent(content[:indent])
15
- indented_lines = add_indent_for_middle_lines(content, mid_indent)
16
- formatted_lines = add_missing_lines(indented_lines, content, mid_indent)
17
- format_for_snbt(formatted_lines, indent, content[:type])
14
+ full_lines = add_missing_lines(content)
15
+ format_for_snbt(full_lines, indent, content)
18
16
  end
19
17
 
20
18
  # SNBT形式に整形
21
19
  #
22
20
  # @param [Array<String>] lines 行
23
21
  # @param [String] indent インデント
24
- # @param [Symbol] type コンテンツの種類
22
+ # @param [Hash] content コンテンツ
25
23
  # @return [String] SNBT形式に整形した行
26
- def format_for_snbt(lines, indent, type)
27
- lines.map! { |line| delete_quotes(line) }
28
- lines.map!(&:strip) unless type == :description
29
-
30
- formatted_lines =
31
- if lines.length == 1
32
- type == :description ? "[#{lines[0].strip}]" : lines[0].strip.to_s
33
- else
34
- # description: [
35
- # "Hello"
36
- # "World"
37
- # ]
38
- "[\n#{lines.join("\n")}\n#{indent}]"
39
- end
40
-
41
- # " description: ["hoge"]"のような形式にする
42
- "#{indent}#{type}: #{formatted_lines}"
24
+ def format_for_snbt(lines, indent, content)
25
+ lines = prepare_lines_for_snbt(lines, content)
26
+ formatted_lines = format_lines(lines, indent, content)
27
+ "#{indent}#{content[:type]}: #{formatted_lines}"
43
28
  end
44
29
 
45
30
  # 不足している行を追加
46
31
  #
47
- # @param [Array<String>] lines 行
48
32
  # @param [Hash] content コンテンツ
49
- # @param [String] middle_indent 中間行のインデント
50
33
  # @return [void]
51
- def add_missing_lines(lines, content, middle_indent)
34
+ def add_missing_lines(content)
52
35
  required_lines = extract_required_line_counts(content)
36
+ lines = content[:text].split("\n")
53
37
 
54
38
  while lines.length < required_lines
55
- lines << empty_middle_line(middle_indent)
39
+ lines << empty_middle_line(content[:indent])
56
40
  end
57
41
 
58
42
  lines
59
43
  end
60
44
 
45
+ private
46
+
47
+ # 不要な文字を削除する
48
+ #
49
+ # @param [String] lines 行
50
+ # @param [Hash] content コンテンツ
51
+ # @return [Array<String>] 不要な文字を削除した行
52
+ def prepare_lines_for_snbt(lines, content)
53
+ lines.map! { |line| delete_quotes(line) }
54
+ lines.map!(&:strip) unless content[:type] == :description
55
+ lines
56
+ end
57
+
58
+ # SNBT形式に変換しやすい形に整形
59
+ #
60
+ # @param [Array<String>] lines 行
61
+ # @param [String] indent インデント
62
+ # @param [Hash] content コンテンツ
63
+ # @return [String] SNBT形式に変換しやすく整形した行
64
+ def format_lines(lines, indent, content)
65
+ if lines.length == 1
66
+ content[:type] == :description ? "[#{lines[0].strip}]" : lines[0].strip.to_s
67
+ else
68
+ # [
69
+ # "Hello"
70
+ # "World"
71
+ # ]
72
+ mid_indent = middle_indent(content[:indent])
73
+ lines = lines.map { |line| "#{mid_indent}#{line.strip}" }
74
+ "[\n#{lines.join("\n")}\n#{indent}]"
75
+ end
76
+ end
77
+
61
78
  # 必要な行数を抽出
62
79
  #
63
80
  # @param [Hash] content コンテンツ
@@ -70,23 +87,11 @@ module JpQuest
70
87
  (content[:end_line] - content[:start_line]) + line_offset - without_brackets
71
88
  end
72
89
 
73
- # 中間行のインデントを追加
74
- #
75
- # @param [Hash] content コンテンツ
76
- # @param [String] middle_indent 中間行のインデント
77
- # @return [Array<String>] 中間行のインデントを追加した行
78
- def add_indent_for_middle_lines(content, middle_indent)
79
- content[:text].split("\n").map do |line|
80
- "#{middle_indent}\"#{line}\""
81
- end
82
- end
83
-
84
90
  # 中間行の空行を作成
85
91
  #
86
- # @param [String] middle_indent 中間行のインデント
87
92
  # @return [String] 空行
88
- def empty_middle_line(middle_indent)
89
- "#{middle_indent}\"\""
93
+ def empty_middle_line(indent)
94
+ middle_indent(indent).to_s
90
95
  end
91
96
 
92
97
  # 不要な引用符を削除
@@ -99,33 +104,17 @@ module JpQuest
99
104
  delete_curved_quotes(line)
100
105
  end
101
106
 
102
- private
103
-
104
107
  # 不要なダブルクオートを削除
105
108
  #
106
109
  # @param [String] line 行
107
110
  # @return [String] 不要なダブルクオートを削除した行
108
111
  def delete_dup_quotes(line)
109
- # ""Hello""、""""
110
- deletable_regs = [/"{2,}.+".*"/, /"{3,}/]
111
- return line unless deletable_regs.any? { |reg| line.match?(reg) }
112
-
113
- # ""
114
- dup_reg = /"{2,}/
115
- # """"に一致する場合は空白行なので、""に変換する
116
- if line.strip.match?(deletable_regs[1])
117
- line.gsub(dup_reg, '""')
118
- else
119
- # 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
120
- line = line.gsub('"', "")
121
- # インデントの調整
122
- indent_count = normalize_indent(line[/^\s*/].length)
123
- line_start = /^(\s*)/
124
- # 行頭にインデントとダブルクオートを追加
125
- line = line.sub(line_start, "#{" " * indent_count}\"")
126
- # 行末のダブルクオートを追加
127
- "#{line}\""
128
- end
112
+ # 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
113
+ # 全て削除したあと、行頭、行末にダブルクオートを追加する
114
+ line = line.gsub('"', "")
115
+ line_start = /^(\s*)/
116
+ line = line.sub(line_start, "\"")
117
+ "#{line}\""
129
118
  end
130
119
 
131
120
  # 不要な鍵括弧を削除
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JpQuest
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -11,7 +11,8 @@ module JpQuest
11
11
  # @return [JpQuest::Writer]
12
12
  def initialize(file_path)
13
13
  @input_file_path = file_path
14
- @output_file_path = file_path.gsub("quests", "output/quests")
14
+ # questsとすると、quests.snbtも変換されてしまうので、quests/とする
15
+ @output_file_path = file_path.gsub("quests/", "output/quests/")
15
16
  @formatter = JpQuest::Formatter.new
16
17
  end
17
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jp_quest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - milkeclair
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-08 00:00:00.000000000 Z
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jp_translator_from_gpt