|
|
@@ -118,55 +118,14 @@ namespace bs
|
|
|
|
|
|
ResourceManifestPath = BuiltinDataFolder + "ResourceManifest.asset";
|
|
|
|
|
|
- // Update from raw assets if needed
|
|
|
- if (FileSystem::exists(BuiltinRawDataFolder))
|
|
|
- {
|
|
|
- time_t lastUpdateTime;
|
|
|
- UINT32 modifications = BuiltinResourcesHelper::checkForModifications(BuiltinRawDataFolder,
|
|
|
- BuiltinDataFolder + "Timestamp.asset", lastUpdateTime);
|
|
|
-
|
|
|
- // Check if manifest needs to be rebuilt
|
|
|
- if (modifications == 0 && !FileSystem::exists(ResourceManifestPath))
|
|
|
- modifications = 1;
|
|
|
-
|
|
|
- if (modifications > 0)
|
|
|
- {
|
|
|
- bool forceReimport = modifications == 2;
|
|
|
-
|
|
|
- SPtr<ResourceManifest> oldResourceManifest;
|
|
|
- if (!forceReimport && FileSystem::exists(ResourceManifestPath))
|
|
|
- {
|
|
|
- oldResourceManifest = ResourceManifest::load(ResourceManifestPath, BuiltinDataFolder);
|
|
|
- if (oldResourceManifest != nullptr)
|
|
|
- gResources().registerResourceManifest(oldResourceManifest);
|
|
|
- }
|
|
|
-
|
|
|
- if (oldResourceManifest)
|
|
|
- mResourceManifest = oldResourceManifest;
|
|
|
- else
|
|
|
- {
|
|
|
- mResourceManifest = ResourceManifest::create("BuiltinResources");
|
|
|
- gResources().registerResourceManifest(mResourceManifest);
|
|
|
- }
|
|
|
-
|
|
|
- preprocess(modifications == 2, lastUpdateTime);
|
|
|
- BuiltinResourcesHelper::writeTimestamp(BuiltinDataFolder + "Timestamp.asset");
|
|
|
-
|
|
|
- ResourceManifest::save(mResourceManifest, ResourceManifestPath, BuiltinDataFolder);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// Load manifest
|
|
|
- if (mResourceManifest == nullptr)
|
|
|
- {
|
|
|
- if (FileSystem::exists(ResourceManifestPath))
|
|
|
- mResourceManifest = ResourceManifest::load(ResourceManifestPath, BuiltinDataFolder);
|
|
|
+ if (FileSystem::exists(ResourceManifestPath))
|
|
|
+ mResourceManifest = ResourceManifest::load(ResourceManifestPath, BuiltinDataFolder);
|
|
|
|
|
|
- if (mResourceManifest == nullptr)
|
|
|
- mResourceManifest = ResourceManifest::create("BuiltinResources");
|
|
|
+ if (mResourceManifest == nullptr)
|
|
|
+ mResourceManifest = ResourceManifest::create("BuiltinResources");
|
|
|
|
|
|
- gResources().registerResourceManifest(mResourceManifest);
|
|
|
- }
|
|
|
+ gResources().registerResourceManifest(mResourceManifest);
|
|
|
|
|
|
// Load basic resources
|
|
|
mShaderDockOverlay = getShader(ShaderDockOverlayFile);
|
|
|
@@ -194,254 +153,6 @@ namespace bs
|
|
|
mSkin = gResources().load<GUISkin>(BuiltinDataFolder + (GUISkinFile + ".asset"));
|
|
|
}
|
|
|
|
|
|
- void BuiltinEditorResources::preprocess(bool forceImport, time_t lastUpdateTime)
|
|
|
- {
|
|
|
- Resources::instance().unloadAllUnused();
|
|
|
-
|
|
|
- Path dataListsFilePath = BuiltinRawDataFolder + DATA_LIST_JSON;
|
|
|
- SPtr<DataStream> dataListStream = FileSystem::openFile(dataListsFilePath);
|
|
|
-
|
|
|
- json dataListJSON = json::parse(dataListStream->getAsString().c_str());
|
|
|
-
|
|
|
- json skinJSON = dataListJSON["Skin"];
|
|
|
- json iconsJSON = dataListJSON["Icons"];
|
|
|
- json includesJSON = dataListJSON["Includes"];
|
|
|
- json shadersJSON = dataListJSON["Shaders"];
|
|
|
-
|
|
|
- // Update DataList.json if needed
|
|
|
- bool updatedDataLists = false;
|
|
|
- updatedDataLists |= BuiltinResourcesHelper::updateJSON(
|
|
|
- EditorRawIconsFolder,
|
|
|
- BuiltinResourcesHelper::AssetType::Sprite,
|
|
|
- iconsJSON);
|
|
|
-
|
|
|
- updatedDataLists |= BuiltinResourcesHelper::updateJSON(
|
|
|
- EditorRawShaderIncludeFolder,
|
|
|
- BuiltinResourcesHelper::AssetType::Normal,
|
|
|
- includesJSON);
|
|
|
-
|
|
|
- updatedDataLists |= BuiltinResourcesHelper::updateJSON(
|
|
|
- EditorRawShaderFolder,
|
|
|
- BuiltinResourcesHelper::AssetType::Normal,
|
|
|
- shadersJSON);
|
|
|
-
|
|
|
- updatedDataLists |= BuiltinResourcesHelper::updateJSON(
|
|
|
- EditorRawSkinFolder,
|
|
|
- BuiltinResourcesHelper::AssetType::Sprite,
|
|
|
- skinJSON);
|
|
|
-
|
|
|
- dataListStream->close();
|
|
|
-
|
|
|
- if (updatedDataLists)
|
|
|
- {
|
|
|
- FileSystem::remove(dataListsFilePath);
|
|
|
-
|
|
|
- dataListJSON["Skin"] = skinJSON;
|
|
|
- dataListJSON["Icons"] = iconsJSON;
|
|
|
- dataListJSON["Includes"] = includesJSON;
|
|
|
- dataListJSON["Shaders"] = shadersJSON;
|
|
|
-
|
|
|
- String jsonString = dataListJSON.dump(4).c_str();
|
|
|
- dataListStream = FileSystem::createAndOpenFile(dataListsFilePath);
|
|
|
- dataListStream->writeString(jsonString);
|
|
|
- dataListStream->close();
|
|
|
- }
|
|
|
-
|
|
|
- // If forcing import, clear all data folders since everything will be recreated anyway
|
|
|
- Path shaderDependenciesFile = BuiltinDataFolder + "ShaderDependencies.json";
|
|
|
- if(forceImport)
|
|
|
- {
|
|
|
- FileSystem::remove(EditorIconFolder);
|
|
|
- FileSystem::remove(EditorShaderIncludeFolder);
|
|
|
- FileSystem::remove(EditorShaderFolder);
|
|
|
- FileSystem::remove(EditorSkinFolder);
|
|
|
-
|
|
|
- FileSystem::remove(shaderDependenciesFile);
|
|
|
- }
|
|
|
-
|
|
|
- // Read shader dependencies JSON
|
|
|
- json shaderDependenciesJSON;
|
|
|
- if(FileSystem::exists(shaderDependenciesFile))
|
|
|
- {
|
|
|
- SPtr<DataStream> stream = FileSystem::openFile(shaderDependenciesFile);
|
|
|
- shaderDependenciesJSON = json::parse(stream->getAsString().c_str());
|
|
|
- stream->close();
|
|
|
- }
|
|
|
-
|
|
|
- // Import icons
|
|
|
- {
|
|
|
- BuiltinResourcesHelper::updateManifest(
|
|
|
- EditorIconFolder,
|
|
|
- iconsJSON,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Sprite);
|
|
|
-
|
|
|
- Vector<bool> importFlags = BuiltinResourcesHelper::generateImportFlags(
|
|
|
- iconsJSON,
|
|
|
- EditorRawIconsFolder,
|
|
|
- lastUpdateTime,
|
|
|
- forceImport);
|
|
|
-
|
|
|
- BuiltinResourcesHelper::importAssets(
|
|
|
- iconsJSON,
|
|
|
- importFlags,
|
|
|
- EditorRawIconsFolder,
|
|
|
- EditorIconFolder,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Sprite);
|
|
|
- }
|
|
|
-
|
|
|
- // Import shaders
|
|
|
- {
|
|
|
- BuiltinResourcesHelper::updateManifest(
|
|
|
- EditorShaderIncludeFolder,
|
|
|
- includesJSON,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Normal);
|
|
|
-
|
|
|
- BuiltinResourcesHelper::updateManifest(
|
|
|
- EditorShaderFolder,
|
|
|
- shadersJSON,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Normal);
|
|
|
-
|
|
|
- Vector<bool> includeImportFlags = BuiltinResourcesHelper::generateImportFlags(
|
|
|
- includesJSON,
|
|
|
- EditorRawShaderIncludeFolder,
|
|
|
- lastUpdateTime,
|
|
|
- forceImport);
|
|
|
-
|
|
|
- Vector<bool> shaderImportFlags = BuiltinResourcesHelper::generateImportFlags(
|
|
|
- shadersJSON,
|
|
|
- EditorRawShaderFolder,
|
|
|
- lastUpdateTime,
|
|
|
- forceImport,
|
|
|
- &shaderDependenciesJSON,
|
|
|
- EditorRawShaderIncludeFolder);
|
|
|
-
|
|
|
- // Hidden dependency: Includes must be imported before shaders, but import flags for shaders must be generated
|
|
|
- // before includes are imported, since the process checks if imports changed
|
|
|
- BuiltinResourcesHelper::importAssets(
|
|
|
- includesJSON,
|
|
|
- includeImportFlags,
|
|
|
- EditorRawShaderIncludeFolder,
|
|
|
- EditorShaderIncludeFolder,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Normal);
|
|
|
-
|
|
|
- BuiltinResourcesHelper::importAssets(
|
|
|
- shadersJSON,
|
|
|
- shaderImportFlags,
|
|
|
- EditorRawShaderFolder,
|
|
|
- EditorShaderFolder,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Normal,
|
|
|
- &shaderDependenciesJSON);
|
|
|
- }
|
|
|
-
|
|
|
- // Import GUI sprites
|
|
|
- {
|
|
|
- BuiltinResourcesHelper::updateManifest(
|
|
|
- EditorSkinFolder,
|
|
|
- skinJSON,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Sprite);
|
|
|
-
|
|
|
- Vector<bool> includeImportFlags = BuiltinResourcesHelper::generateImportFlags(
|
|
|
- skinJSON,
|
|
|
- EditorRawSkinFolder,
|
|
|
- lastUpdateTime,
|
|
|
- forceImport);
|
|
|
-
|
|
|
- BuiltinResourcesHelper::importAssets(
|
|
|
- skinJSON,
|
|
|
- includeImportFlags,
|
|
|
- EditorRawSkinFolder,
|
|
|
- EditorSkinFolder,
|
|
|
- mResourceManifest,
|
|
|
- BuiltinResourcesHelper::AssetType::Sprite);
|
|
|
- }
|
|
|
-
|
|
|
- // Update shader dependencies JSON
|
|
|
- {
|
|
|
- String jsonString = shaderDependenciesJSON.dump(4).c_str();
|
|
|
-
|
|
|
- dataListStream = FileSystem::createAndOpenFile(shaderDependenciesFile);
|
|
|
- dataListStream->writeString(jsonString);
|
|
|
- dataListStream->close();
|
|
|
- }
|
|
|
-
|
|
|
- // Import fonts
|
|
|
- BuiltinResourcesHelper::importFont(
|
|
|
- BuiltinRawDataFolder + DefaultFontFilename,
|
|
|
- DefaultFontFilename,
|
|
|
- BuiltinDataFolder,
|
|
|
- { DefaultFontSize },
|
|
|
- true,
|
|
|
- UUID("6ce69053-00d7-4c60-a229-249b8d8fd60e"),
|
|
|
- mResourceManifest);
|
|
|
-
|
|
|
- BuiltinResourcesHelper::importFont(
|
|
|
- BuiltinRawDataFolder + DefaultFontFilename,
|
|
|
- DefaultAAFontFilename,
|
|
|
- BuiltinDataFolder,
|
|
|
- { TitleFontSize },
|
|
|
- true,
|
|
|
- UUID("10999b74-d976-4116-9f72-21e489a7a8e4"),
|
|
|
- mResourceManifest);
|
|
|
-
|
|
|
- // Import splash screen
|
|
|
- {
|
|
|
- Path inputPath = BuiltinRawDataFolder + String(SplashScreenName);
|
|
|
- Path outputPath = BuiltinDataFolder + (String(SplashScreenName) + ".asset");
|
|
|
-
|
|
|
- auto textureIO = gImporter().createImportOptions<TextureImportOptions>(inputPath);
|
|
|
- textureIO->setCPUCached(true);
|
|
|
- textureIO->setGenerateMipmaps(false);
|
|
|
- HTexture splashTexture = gImporter().import<Texture>(inputPath, textureIO);
|
|
|
-
|
|
|
- SPtr<PixelData> splashPixelData = splashTexture->getProperties().allocBuffer(0, 0);
|
|
|
- splashTexture->readCachedData(*splashPixelData);
|
|
|
-
|
|
|
- FileEncoder fe(outputPath);
|
|
|
- fe.encode(splashPixelData.get());
|
|
|
- }
|
|
|
-
|
|
|
- // Generate & save GUI skin
|
|
|
- {
|
|
|
- SPtr<GUISkin> skin = generateGUISkin();
|
|
|
- Path outputPath = BuiltinDataFolder + (GUISkinFile + ".asset");
|
|
|
-
|
|
|
- HResource skinResource = gResources()._createResourceHandle(skin, UUID("ec0ea68d-efa5-4a3b-a6fc-b15aaec9689f"));
|
|
|
-
|
|
|
- gResources().save(skinResource, outputPath, true);
|
|
|
- mResourceManifest->registerResource(skinResource.getUUID(), outputPath);
|
|
|
- }
|
|
|
-
|
|
|
- Resources::instance().unloadAllUnused();
|
|
|
- }
|
|
|
-
|
|
|
- SPtr<GUISkin> BuiltinEditorResources::generateGUISkin()
|
|
|
- {
|
|
|
- BuiltinResourceGUIElementStyleLoader loader(BuiltinDataFolder, EditorSkinSpritesFolder);
|
|
|
-
|
|
|
- Path guiSkinPath = BuiltinRawDataFolder + GUI_SKIN_JSON;
|
|
|
- SPtr<DataStream> guiSkinStream = FileSystem::openFile(guiSkinPath);
|
|
|
- json guiSkinJSON = json::parse(guiSkinStream->getAsString().c_str());
|
|
|
-
|
|
|
- SPtr<GUISkin> skin = GUISkin::_createPtr();
|
|
|
-
|
|
|
- for (auto& entry : guiSkinJSON)
|
|
|
- {
|
|
|
- std::string name = entry["name"];
|
|
|
-
|
|
|
- GUIElementStyle style = BuiltinResourcesHelper::loadGUIStyleFromJSON(entry, loader);
|
|
|
- skin->setStyle(name.c_str(), style);
|
|
|
- }
|
|
|
-
|
|
|
- return skin;
|
|
|
- }
|
|
|
-
|
|
|
HSpriteTexture BuiltinEditorResources::getGUIIcon(const String& name) const
|
|
|
{
|
|
|
Path texturePath = EditorIconSpritesFolder;
|