|
1 | 1 | extends Node
|
2 | 2 |
|
| 3 | +func load_extra_images_from_harddrive(): |
| 4 | + var CODETIME_START = OS.get_ticks_msec() |
| 5 | + var custom_images_dir = Settings.unearthdata.plus_file("custom-object-images") |
| 6 | + var image_paths = get_png_files_in_dir(custom_images_dir) |
| 7 | + for image_path in image_paths: |
| 8 | + var texture = load(image_path) |
| 9 | + if texture is Texture: |
| 10 | + var image_name = image_path.get_file().get_basename().to_upper() |
| 11 | + sprite_id[image_name] = texture |
| 12 | + else: |
| 13 | + print("Failed to load texture: ", image_path) |
| 14 | + print('Loaded extra images from HDD: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms') |
| 15 | + |
| 16 | +func get_png_files_in_dir(path): |
| 17 | + var png_files = [] |
| 18 | + var dir = Directory.new() |
| 19 | + if dir.open(path) == OK: |
| 20 | + dir.list_dir_begin() |
| 21 | + var file_name = dir.get_next() |
| 22 | + while file_name != "": |
| 23 | + if not dir.current_is_dir() and file_name.get_extension().to_lower() == "png": |
| 24 | + png_files.append(path.plus_file(file_name)) |
| 25 | + file_name = dir.get_next() |
| 26 | + else: |
| 27 | + print("An error occurred when trying to access the directory: ", path) |
| 28 | + return png_files |
| 29 | + |
| 30 | + |
| 31 | +#func load_custom_images_into_array(DATA_ARRAY, thingtypeImageFolder): |
| 32 | +# print("Loading /thing-images/" + thingtypeImageFolder + " directory ...") |
| 33 | +# var arrayOfFilenames = get_png_files_in_dir(Settings.unearthdata.plus_file("thing-images").plus_file(thingtypeImageFolder)) |
| 34 | +# for i in arrayOfFilenames: |
| 35 | +# var subtypeID = int(i.get_file().get_basename()) |
| 36 | +# var img = Image.new() |
| 37 | +# var err = img.load(i) |
| 38 | +# if err == OK: |
| 39 | +# var tex = ImageTexture.new() |
| 40 | +# tex.create_from_image(img) |
| 41 | +# if DATA_ARRAY.has(subtypeID): |
| 42 | +# DATA_ARRAY[subtypeID][TEXTURE] = tex |
| 43 | + |
| 44 | + |
| 45 | +#func look_for_images_to_load(DATA_ARRAY, objectID, thingCfgName): |
| 46 | +# if custom_images_list.empty() == true: |
| 47 | +# custom_images_list = get_png_filenames_in_dir(Settings.unearthdata.plus_file("custom-object-images")) |
| 48 | +# |
| 49 | +# var dir = Settings.unearthdata.plus_file("custom-object-images") |
| 50 | +# |
| 51 | +# var uppercaseImageFilename = thingCfgName+".PNG".to_upper() |
| 52 | +# var uppercasePortraitFilename = thingCfgName+"_PORTRAIT.PNG".to_upper() |
| 53 | +# |
| 54 | +# var realImageFilename = "" |
| 55 | +# var realPortraitFilename = "" |
| 56 | +# |
| 57 | +# if custom_images_list.has(uppercaseImageFilename): |
| 58 | +# realImageFilename = custom_images_list[uppercaseImageFilename] |
| 59 | +# |
| 60 | +# if custom_images_list.has(uppercasePortraitFilename): |
| 61 | +# realPortraitFilename = custom_images_list[uppercasePortraitFilename] |
| 62 | +# |
| 63 | +# if realImageFilename != "": |
| 64 | +# var img = Image.new() |
| 65 | +# var err = img.load(dir.plus_file(realImageFilename)) |
| 66 | +# if err == OK: |
| 67 | +# var tex = ImageTexture.new() |
| 68 | +# tex.create_from_image(img, Texture.FLAG_MIPMAPS+Texture.FLAG_ANISOTROPIC_FILTER) |
| 69 | +# #DATA_ARRAY[objectID][Things.TEXTURE] = tex |
| 70 | +# |
| 71 | +# if realPortraitFilename != "": |
| 72 | +# var img = Image.new() |
| 73 | +# var err = img.load(dir.plus_file(realPortraitFilename)) |
| 74 | +# if err == OK: |
| 75 | +# var tex = ImageTexture.new() |
| 76 | +# tex.create_from_image(img, Texture.FLAG_MIPMAPS+Texture.FLAG_ANISOTROPIC_FILTER) |
| 77 | +# #DATA_ARRAY[objectID][Things.PORTRAIT] = tex |
| 78 | +# |
| 79 | +#func get_png_filenames_in_dir(path): |
| 80 | +# var dictionary = {} |
| 81 | +# var dir = Directory.new() |
| 82 | +# if dir.open(path) == OK: |
| 83 | +# dir.list_dir_begin() |
| 84 | +# var file_name = dir.get_next() |
| 85 | +# while file_name != "": |
| 86 | +# if dir.current_is_dir(): |
| 87 | +# pass |
| 88 | +# else: |
| 89 | +# if file_name.get_extension().to_upper() == "PNG": |
| 90 | +# dictionary[file_name.to_upper().replace(" ", "_")] = file_name |
| 91 | +# file_name = dir.get_next() |
| 92 | +# else: |
| 93 | +# print("An error occurred when trying to access the path.") |
| 94 | +# return dictionary |
| 95 | +# |
| 96 | +#func get_png_files_in_dir(path): |
| 97 | +# var array = [] |
| 98 | +# var dir = Directory.new() |
| 99 | +# if dir.open(path) == OK: |
| 100 | +# dir.list_dir_begin() |
| 101 | +# var file_name = dir.get_next() |
| 102 | +# while file_name != "": |
| 103 | +# if dir.current_is_dir(): |
| 104 | +# pass |
| 105 | +# else: |
| 106 | +# if file_name.get_extension().to_upper() == "PNG": |
| 107 | +# var fileNumber = file_name.get_file().get_basename() |
| 108 | +# if Utils.string_has_letters(fileNumber) == false: |
| 109 | +# array.append(path.plus_file(file_name)) |
| 110 | +# file_name = dir.get_next() |
| 111 | +# else: |
| 112 | +# print("An error occurred when trying to access the path.") |
| 113 | +# return array |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
3 | 118 | # The keys can be integers or strings (as read from objects.cfg's AnimationID field)
|
4 | 119 | # When they're a String, they can be either read the 'Name' field or the 'AnimationID' field, whichever one is prioritized
|
5 | 120 | var sprite_id = {
|
|
0 commit comments