Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | 32x 32x 32x 32x 32x 32x 32x 25x 25x 32x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 19x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 1x 20x 20x 1x 1x 1x 1x 1x | import Path from "path"; import { ActorPrefabResource, ActorResource, AvatarResource, CompressedBackgroundResource, CompressedProjectResources, CompressedSceneResource, EmoteResource, EngineFieldValuesResource, FontResource, MusicResource, PaletteResource, ScriptResource, SettingsResource, SoundResource, SpriteResource, TilesetResource, TriggerPrefabResource, TriggerResource, VariablesResource, WriteFile, } from "shared/lib/resources/types"; import { getActorPrefabResourcePath, getActorResourcePath, getPaletteResourcePath, getSceneFolderPath, getSceneResourcePath, getScriptResourcePath, getTriggerPrefabResourcePath, getTriggerResourcePath, projectResourcesFolder, } from "shared/lib/resources/paths"; import SparkMD5 from "spark-md5"; import { omit } from "shared/types"; import { assetPath } from "shared/lib/helpers/assets"; const userSettingKeys: (keyof SettingsResource)[] = [ "worldScrollX", "worldScrollY", "zoom", "navigatorSplitSizes", "showNavigator", "showCollisions", "showConnections", "previewAsMono", "showCollisionSlopeTiles", "showCollisionSlopeTiles", "favoriteEvents", "debuggerEnabled", "debuggerScriptType", "debuggerVariablesFilter", "debuggerCollapsedPanes", "debuggerPauseOnScriptChanged", "debuggerPauseOnWatchedVariableChanged", "debuggerBreakpoints", "debuggerWatchedVariables", "openBuildLogOnWarnings", ]; export const encodeResource = <T extends Record<string, unknown>>( resourceType: string, data: T ): string => { const { // Extract id so it can be moved to top of data id, // Remove internal data so it isn't stored to disk __type, // Extract remaining data to write to disk ...rest } = data; return JSON.stringify( { _resourceType: resourceType, id, ...rest, }, null, 2 ); }; export const buildResourceExportBuffer = ( projectResources: CompressedProjectResources ): WriteFile[] => { const variablesResFilename = Path.join( projectResourcesFolder, `variables.gbsres` ); const settingsResFilename = Path.join( projectResourcesFolder, `settings.gbsres` ); const userSettingsResFilename = Path.join( projectResourcesFolder, `user_settings.gbsres` ); const engineFieldValuesResFilename = Path.join( projectResourcesFolder, `engine_field_values.gbsres` ); const writeBuffer: WriteFile[] = []; const seenPaths = new Set<string>(); const getUniquePath = (path: string): string => { if (!seenPaths.has(path)) { seenPaths.add(path); return path; } const basename = Path.basename(path); const dirname = Path.dirname(path); const newPath = Path.join( dirname, basename.replace( /([0-9]*)(\.[^.]+|)$/, (_, number, ext) => `${number ? parseInt(number) + 1 : `_2`}${ext}` ) ); return getUniquePath(newPath); }; const writeResource = <T extends Record<string, unknown>>( filename: string, resourceType: string, resource: T ) => { const data = encodeResource(resourceType, resource); writeBuffer.push({ path: filename, checksum: SparkMD5.hash(data), data, }); }; let sceneIndex = 0; for (const scene of projectResources.scenes) { const sceneFolder = getUniquePath(getSceneFolderPath(scene)); const sceneFilename = getUniquePath(getSceneResourcePath(sceneFolder)); // Scene Actors if (scene.actors.length > 0) { let actorIndex = 0; for (const actor of scene.actors) { if (actor) { const actorFilename = getUniquePath( getActorResourcePath(sceneFolder, actor) ); writeResource<ActorResource>(actorFilename, "actor", { ...actor, _index: actorIndex, }); actorIndex++; } } } // Scene Triggers if (scene.triggers.length > 0) { let triggerIndex = 0; for (const trigger of scene.triggers) { if (trigger) { const triggerFilename = getUniquePath( getTriggerResourcePath(sceneFolder, trigger) ); writeResource<TriggerResource>(triggerFilename, "trigger", { ...trigger, _index: triggerIndex, }); triggerIndex++; } } } writeResource<CompressedSceneResource>(sceneFilename, "scene", { ...omit(scene, "actors", "triggers"), _index: sceneIndex, }); sceneIndex++; } for (const background of projectResources.backgrounds) { const assetFilename = assetPath("backgrounds", background); const resFilename = assetFilename + ".gbsres"; writeResource<CompressedBackgroundResource>( resFilename, "background", background ); } for (const sprite of projectResources.sprites) { const assetFilename = assetPath("sprites", sprite); const resFilename = assetFilename + ".gbsres"; writeResource<SpriteResource>(resFilename, "sprite", sprite); } for (const palette of projectResources.palettes) { const paletteFilename = getUniquePath(getPaletteResourcePath(palette)); writeResource<PaletteResource>(paletteFilename, "palette", palette); } for (const actorPrefab of projectResources.actorPrefabs) { const actorPrefabFilename = getUniquePath( getActorPrefabResourcePath(actorPrefab) ); writeResource<ActorPrefabResource>( actorPrefabFilename, "actorPrefab", actorPrefab ); } for (const triggerPrefab of projectResources.triggerPrefabs) { const triggerPrefabFilename = getUniquePath( getTriggerPrefabResourcePath(triggerPrefab) ); writeResource<TriggerPrefabResource>( triggerPrefabFilename, "triggerPrefab", triggerPrefab ); } for (const script of projectResources.scripts) { const scriptFilename = getUniquePath(getScriptResourcePath(script)); writeResource<ScriptResource>(scriptFilename, "script", script); } for (const song of projectResources.music) { const assetFilename = assetPath("music", song); const resFilename = assetFilename + ".gbsres"; writeResource<MusicResource>(resFilename, "music", song); } for (const sound of projectResources.sounds) { const assetFilename = assetPath("sounds", sound); const resFilename = assetFilename + ".gbsres"; writeResource<SoundResource>(resFilename, "sound", sound); } for (const emote of projectResources.emotes) { const assetFilename = assetPath("emotes", emote); const resFilename = assetFilename + ".gbsres"; writeResource<EmoteResource>(resFilename, "emote", emote); } for (const avatar of projectResources.avatars) { const assetFilename = assetPath("avatars", avatar); const resFilename = assetFilename + ".gbsres"; writeResource<AvatarResource>(resFilename, "avatar", avatar); } for (const tileset of projectResources.tilesets) { const assetFilename = assetPath("tilesets", tileset); const resFilename = assetFilename + ".gbsres"; writeResource<TilesetResource>(resFilename, "tileset", tileset); } for (const font of projectResources.fonts) { const assetFilename = assetPath("fonts", font); const resFilename = assetFilename + ".gbsres"; writeResource<FontResource>(resFilename, "font", font); } const clearedSettings = userSettingKeys.reduce((acc, key) => { acc[key] = undefined; return acc; }, {} as Partial<SettingsResource>); const userSettings = userSettingKeys.reduce( <T extends keyof SettingsResource>( acc: Partial<SettingsResource>, key: T ) => { acc[key] = projectResources.settings[key] as SettingsResource[T]; return acc; }, {} as Partial<SettingsResource> ); writeResource<Partial<SettingsResource>>(settingsResFilename, "settings", { ...projectResources.settings, ...clearedSettings, }); writeResource<Partial<SettingsResource>>( userSettingsResFilename, "settings", userSettings ); writeResource<VariablesResource>( variablesResFilename, "variables", projectResources.variables ); writeResource<EngineFieldValuesResource>( engineFieldValuesResFilename, "engineFieldValues", projectResources.engineFieldValues ); return writeBuffer; }; |