|
| 1 | +#include "assetsManager.h" |
| 2 | + |
| 3 | +std::vector<Kana> loadAssets() |
| 4 | +{ |
| 5 | + std::vector<Kana> kanas; |
| 6 | + kanas.reserve(142); |
| 7 | + |
| 8 | + std::string audioPath = "assets/sounds/"; |
| 9 | + std::string hiraganaImgsPath = "assets/img/hiraganas/"; |
| 10 | + std::string audioExtension = ".mp3"; |
| 11 | + std::string imageExtension = ".png"; |
| 12 | + std::string hiraganaGifPath = "assets/gifs/hiraganas/"; |
| 13 | + std::string gifExtension = ".gif"; |
| 14 | + |
| 15 | + std::string kanaNames[] = { |
| 16 | + "a", "e", "i", "o", "u", |
| 17 | + "ka", "ga", "ki", "gi", "ku", |
| 18 | + "gu", "ke", "ge", "ko", "go", |
| 19 | + "sa", "za", "shi", "ji", "su", |
| 20 | + "zu", "se", "ze", "so", "zo", |
| 21 | + "ta", "da", "chi", "di", "tsu", |
| 22 | + "du", "te", "de", "to", "do", |
| 23 | + "na", "ni", "nu", "ne", "no", |
| 24 | + "ha", "ba", "pa", "hi", "bi", |
| 25 | + "pi", "fu", "bu", "pu", "he", |
| 26 | + "be", "pe", "ho", "bo", "po", |
| 27 | + "ma", "mi", "mu", "me", "mo", |
| 28 | + "ya", "yu", "yo", |
| 29 | + "ra", "ri", "ru", "re", "ro", |
| 30 | + "wa", "wo", "n" |
| 31 | + }; |
| 32 | + |
| 33 | + for (std::string &kanaName : kanaNames) |
| 34 | + { |
| 35 | + std::string actualAudioPath = audioPath + kanaName + audioExtension; |
| 36 | + Sound actualSound = LoadSound(actualAudioPath.c_str()); |
| 37 | + SetSoundVolume(actualSound, 0.8); |
| 38 | + |
| 39 | + std::string actualImagePath = hiraganaImgsPath + kanaName + imageExtension; |
| 40 | + Texture2D actualTexture = LoadTexture(actualImagePath.c_str()); |
| 41 | + Rectangle kanaBounds = {40, 40, (float)actualTexture.width, (float)actualTexture.height}; |
| 42 | + |
| 43 | + std::string actualGifPath = hiraganaGifPath + kanaName + gifExtension; |
| 44 | + |
| 45 | + int animationFrames = 0; |
| 46 | + // Since I'm loading images, the ram consumption will go up. |
| 47 | + // Load all GIF animation frames into a single Image |
| 48 | + // NOTE: GIF data is always loaded as RGBA (32bit) by default |
| 49 | + // NOTE: Frames are just appended one after another in image.data memory |
| 50 | + Image kanaAnimation = LoadImageAnim(actualGifPath.c_str(), &animationFrames); |
| 51 | + |
| 52 | + // Load texture from image |
| 53 | + // NOTE: We will update this texture when required with next frame data |
| 54 | + // WARNING: It's not recommended to use this technique for sprites animation, |
| 55 | + // use spritesheets instead, like illustrated in textures_sprite_anim example |
| 56 | + Texture2D drawKanaTexture = LoadTextureFromImage(kanaAnimation); |
| 57 | + |
| 58 | + kanas.push_back({kanaName, kanaBounds, actualTexture, actualSound, drawKanaTexture, kanaAnimation, animationFrames}); |
| 59 | + } |
| 60 | + |
| 61 | + std::string katakanaImgsPath = "assets/img/katakanas/"; |
| 62 | + std::string katakanaGifPath = "assets/gifs/katakanas/"; |
| 63 | + |
| 64 | + int actualMaxSize = kanas.size(); |
| 65 | + |
| 66 | + for (int i = 0; i < actualMaxSize; i++) |
| 67 | + { |
| 68 | + auto actualKana = kanas[i]; |
| 69 | + |
| 70 | + std::string actualImagePath = katakanaImgsPath + actualKana.name + imageExtension; |
| 71 | + Texture2D actualTexture = LoadTexture(actualImagePath.c_str()); |
| 72 | + Rectangle kanaBounds = {40, 40, (float)actualTexture.width, (float)actualTexture.height}; |
| 73 | + |
| 74 | + std::string actualGifPath = katakanaGifPath + actualKana.name + gifExtension; |
| 75 | + |
| 76 | + int animationFrames = 0; |
| 77 | + Image kanaAnimation = LoadImageAnim(actualGifPath.c_str(), &animationFrames); |
| 78 | + |
| 79 | + Texture2D drawKanaTexture = LoadTextureFromImage(kanaAnimation); |
| 80 | + |
| 81 | + kanas.push_back({actualKana.name, kanaBounds, actualTexture, actualKana.sound, drawKanaTexture, kanaAnimation, animationFrames}); |
| 82 | + } |
| 83 | + |
| 84 | + return kanas; |
| 85 | +} |
| 86 | + |
| 87 | +std::string handleMissingGifName(std::string kanaName) |
| 88 | +{ |
| 89 | + std::string actualName = kanaName; |
| 90 | + |
| 91 | + if (actualName.compare("ji") == 0) |
| 92 | + { |
| 93 | + actualName = "shi"; |
| 94 | + } |
| 95 | + |
| 96 | + if (actualName.compare("gi") == 0) |
| 97 | + { |
| 98 | + actualName = "ki"; |
| 99 | + } |
| 100 | + |
| 101 | + else if (actualName.compare("ga") == 0) |
| 102 | + { |
| 103 | + actualName = "ka"; |
| 104 | + } |
| 105 | + |
| 106 | + else if (actualName.compare("ge") == 0) |
| 107 | + { |
| 108 | + actualName = "ke"; |
| 109 | + } |
| 110 | + |
| 111 | + else if (actualName.compare("go") == 0) |
| 112 | + { |
| 113 | + actualName = "ko"; |
| 114 | + } |
| 115 | + |
| 116 | + else if (actualName.compare("gu") == 0) |
| 117 | + { |
| 118 | + actualName = "ku"; |
| 119 | + } |
| 120 | + |
| 121 | + else if (actualName.compare("za") == 0) |
| 122 | + { |
| 123 | + actualName = "sa"; |
| 124 | + } |
| 125 | + |
| 126 | + else if (actualName.compare("ze") == 0) |
| 127 | + { |
| 128 | + actualName = "se"; |
| 129 | + } |
| 130 | + |
| 131 | + else if (actualName.compare("zo") == 0) |
| 132 | + { |
| 133 | + actualName = "so"; |
| 134 | + } |
| 135 | + |
| 136 | + else if (actualName.compare("zu") == 0) |
| 137 | + { |
| 138 | + actualName = "su"; |
| 139 | + } |
| 140 | + |
| 141 | + else if (actualName.compare("da") == 0) |
| 142 | + { |
| 143 | + actualName = "ta"; |
| 144 | + } |
| 145 | + |
| 146 | + else if (actualName.compare("de") == 0) |
| 147 | + { |
| 148 | + actualName = "te"; |
| 149 | + } |
| 150 | + |
| 151 | + else if (actualName.compare("do") == 0) |
| 152 | + { |
| 153 | + actualName = "to"; |
| 154 | + } |
| 155 | + |
| 156 | + else if (actualName.compare("di") == 0) |
| 157 | + { |
| 158 | + actualName = "chi"; |
| 159 | + } |
| 160 | + |
| 161 | + else if (actualName.compare("du") == 0) |
| 162 | + { |
| 163 | + actualName = "tsu"; |
| 164 | + } |
| 165 | + |
| 166 | + else if (actualName.compare("ba") == 0 || actualName.compare("pa") == 0) |
| 167 | + { |
| 168 | + actualName = "ha"; |
| 169 | + } |
| 170 | + |
| 171 | + else if (actualName.compare("bo") == 0 || actualName.compare("po") == 0) |
| 172 | + { |
| 173 | + actualName = "ho"; |
| 174 | + } |
| 175 | + |
| 176 | + else if (actualName.compare("be") == 0 || actualName.compare("pe") == 0) |
| 177 | + { |
| 178 | + actualName = "he"; |
| 179 | + } |
| 180 | + |
| 181 | + else if (actualName.compare("bi") == 0 || actualName.compare("pi") == 0) |
| 182 | + { |
| 183 | + actualName = "hi"; |
| 184 | + } |
| 185 | + |
| 186 | + else if (actualName.compare("bu") == 0 || actualName.compare("pu") == 0) |
| 187 | + { |
| 188 | + actualName = "fu"; |
| 189 | + } |
| 190 | + |
| 191 | + return actualName; |
| 192 | +} |
0 commit comments