|
1 | 1 | @tool |
| 2 | +class_name MMLoader |
2 | 3 | extends Node |
3 | 4 |
|
4 | 5 | var predefined_generators : Dictionary = {} |
@@ -157,20 +158,50 @@ static func string_to_dict_tree(string_data : String) -> Dictionary: |
157 | 158 | static func dict_tree_to_string(data : Dictionary) -> String: |
158 | 159 | return JSON.stringify(replace_multiline_strings_with_arrays(data.duplicate(true)), "\t", true) |
159 | 160 |
|
| 161 | +static func interpret_file_name(file_name : String, path : String = "", file_extension : String = "", node : MMGenBase = null, additional_identifiers : Dictionary[String, String] = {}, resolution : String = "") -> String: |
| 162 | + for i in additional_identifiers: |
| 163 | + file_name = file_name.replace(i, additional_identifiers[i]) |
| 164 | + |
| 165 | + if node and node.has_meta("file_path"): |
| 166 | + var save_path : String = node.get_meta("file_path") |
| 167 | + file_name = file_name.replace("$project", save_path.get_file().trim_suffix("."+save_path.get_extension())) |
| 168 | + else: |
| 169 | + file_name = file_name.replace("$project", "unnamed_project") |
| 170 | + |
| 171 | + if file_extension != "" and not file_name.ends_with(file_extension): |
| 172 | + file_name += file_extension |
| 173 | + |
| 174 | + if resolution: |
| 175 | + file_name = file_name.replace("$resolution", resolution) |
| 176 | + |
| 177 | + if "$idx" in file_name: |
| 178 | + if path: |
| 179 | + var idx := 1 |
| 180 | + while FileAccess.file_exists(path.path_join(file_name).replace("$idx", str(idx).pad_zeros(2))): |
| 181 | + idx += 1 |
| 182 | + file_name = file_name.replace("$idx", str(idx).pad_zeros(2)) |
| 183 | + else: |
| 184 | + file_name = file_name.replace("$idx", str(1).pad_zeros(2)) |
| 185 | + |
| 186 | + return file_name |
| 187 | + |
160 | 188 | func load_gen(filename: String) -> MMGenBase: |
161 | 189 | var file : FileAccess = FileAccess.open(filename, FileAccess.READ) |
162 | 190 | if file != null: |
163 | 191 | var data = string_to_dict_tree(file.get_as_text()) |
164 | 192 | if data != null: |
165 | 193 | current_project_path = filename.get_base_dir() |
166 | 194 | var generator = await create_gen(data) |
| 195 | + if generator: |
| 196 | + generator.set_meta("file_path", filename) |
167 | 197 | current_project_path = "" |
168 | 198 | return generator |
169 | 199 | return null |
170 | 200 |
|
171 | 201 | func save_gen(filename : String, generator : MMGenBase) -> void: |
172 | 202 | var file : FileAccess = FileAccess.open(filename, FileAccess.WRITE) |
173 | 203 | if file != null: |
| 204 | + generator.set_meta("file_path", filename) |
174 | 205 | var data = generator.serialize() |
175 | 206 | data.name = filename.get_file().get_basename() |
176 | 207 | data.node_position = { x=0, y=0 } |
|
0 commit comments