Game.PdxAssetUploadHandle
Assembly: Assembly-CSharp
Namespace: Game.UI.Menu
Type: class
Base: System.Object
Summary:
{{ The PdxAssetUploadHandle class encapsulates the logic required to prepare, package and submit assets (mods, previews, screenshots and dependencies) to the Paradox Mods platform via the PdxSdkPlatform. It manages local temporary asset copies, builds dependency caches, handles preview/screenshot copying, optional virtual texturing processing, tag collection and platform interactions (register/update/publish WIP). This class is intended for use by the in-game mod upload UI and related tooling. }}
Fields
-
private ILog log = LogManager.GetLogger("AssetUpload")
{{ Logger used for verbose/info/warn/error messages during packaging and upload operations. }} -
private PdxSdkPlatform m_Manager = PlatformManager.instance.GetPSI<PdxSdkPlatform>("PdxSdk")
{{ Cached reference to the Pdx SDK integration (platform service integration) used to call Paradox Mods APIs. Reinitialised when platform is (re)registered. }} -
private List<AssetData> m_Screenshots = new List<AssetData>()
{{ In-memory list of screenshot assets that will be copied into the mod package metadata. }} -
private List<AssetData> m_Assets = new List<AssetData>()
{{ Primary assets to be included in the package (includes mainAsset if provided). }} -
private List<AssetData> m_OriginalPreviews = new List<AssetData>()
{{ Set of original preview images discovered for the selected assets; used to initialize preview/screenshot lists. }} -
private Dictionary<AssetData, AssetData> m_WIPAssets = new Dictionary<AssetData, AssetData>()
{{ Tracks temporary/working assets created in the ParadoxMods database during packaging so they can be cleaned up later. Key and value are the same for stored package assets. }} -
private List<AssetData> m_AdditionalAssets = new List<AssetData>()
{{ Extra assets (not part of the primary set) that should be included in the upload. }} -
private HashSet<AssetData> m_CachedAssetDependencies = new HashSet<AssetData>()
{{ Cached dependency set collected from all assets (used to build upload dependency list and to know what to pack). }} -
public Action onSocialProfileSynced
{{ Optional callback invoked when the social profile has been refreshed from the platform. }}
Properties
-
public AssetData mainAsset { get; private set }
{{ The primary asset (if any) representing the uploaded item (e.g., primary mod or map). Readable publicly; set privately by constructors. }} -
public IReadOnlyList<AssetData> assets => m_Assets
{{ Read-only view of the primary assets included in the upload package. }} -
public IReadOnlyList<AssetData> additionalAssets => m_AdditionalAssets
{{ Read-only view of additional assets included alongside primary assets. }} -
public HashSet<AssetData> cachedDependencies => m_CachedAssetDependencies
{{ Exposes the collected dependency cache for callers; updated when RebuildDependencyCache() is invoked. }} -
public bool hasPrefabAssets { get; private set; }
{{ True if any of the collected assets are prefab assets (used to trigger prefab-specific handling). }} -
public IEnumerable<AssetData> allAssets
{{ Enumerates both primary and additional assets (primary assets first). Convenient for iterating everything that will be packaged. }} -
public IReadOnlyList<AssetData> screenshots => m_Screenshots
{{ Read-only list of screenshot assets to include as metadata. }} -
public AssetData preview { get; private set; }
{{ Current preview image selected for the upload. Defaults to a found preview or a global default. }} -
public IReadOnlyList<AssetData> originalPreviews => m_OriginalPreviews
{{ Original previews discovered when the handle was initialized; can be used to restore defaults. }} -
public IModsUploadSupport.ModInfo modInfo { get; set; }
{{ Data structure containing metadata (title, tags, dependencies, filenames, root path, etc.) for the upload. Initialized in Initialize() and updated during BeginSubmit/FinalizeSubmit. }} -
public bool updateExisting { get; set; }
{{ If true, operations will update an existing WIP/mod rather than registering a new one. }} -
public int processVT { get; set; } = -1
{{ If >= 0, indicates a mipBias or similar parameter for virtual texturing processing step during CopyFiles. Default -1 means skip VT processing. }} -
public bool packThumbnailsAtlas { get; set; }
{{ When true, an atlas of thumbnails will be generated and included in the package. }} -
public List<IModsUploadSupport.ModInfo> authorMods { get; private set; } = new List<IModsUploadSupport.ModInfo>()
{{ Cached list of mods by the author (populated by SyncPlatformData). }} -
public IModsUploadSupport.ModTag[] availableTags { get; private set; } = Array.Empty<IModsUploadSupport.ModTag>()
{{ Tags available from the platform for categorizing the upload. }} -
public IModsUploadSupport.DLCTag[] availableDLCs { get; private set; } = Array.Empty<IModsUploadSupport.DLCTag>()
{{ DLC tags fetched from the platform to indicate content dependencies. }} -
public HashSet<string> typeTags { get; private set; } = new HashSet<string>()
{{ Tags that indicate asset types (collected from assets). Used to filter available mods etc. }} -
public HashSet<string> tags { get; private set; } = new HashSet<string>()
{{ Selected platform tags for this upload (populated / edited by UI). }} -
public List<string> additionalTags { get; private set; } = new List<string>()
{{ Extra free-form tags the user can add beyond platform-provided tags. }} -
public int tagCount => tags.Count + additionalTags.Count
{{ Convenience property returning total number of tags assigned. }} -
public bool binaryPackAssets { get; set; } = true
{{ Whether to perform binary packing of assets when copying (affects how assets are exported into the local temporary DB). }} -
public IModsUploadSupport.SocialProfile socialProfile { get; private set; }
{{ Cached social profile details for the author. }}
Constructors
-
public PdxAssetUploadHandle()
{{ Default constructor. Initializes manager reference, preview defaults, modInfo defaults (recommended game version and an empty external link), and rebuilds dependency cache. Use when you will assign assets later. }} -
public PdxAssetUploadHandle(AssetData mainAsset, params AssetData[] assets)
{{ Constructor that sets mainAsset and adds provided assets to the primary list, then runs initialization (Initialize). Useful when starting an upload flow for a specific asset and optional additional assets. }}
Methods
-
public bool LoggedIn()
{{ Returns whether the Pdx SDK platform reports a cached logged-in state. Quick check before attempting platform operations. }} -
public async Task<IModsUploadSupport.ModOperationResult> BeginSubmit()
{{ Registers (or gets an existing) WIP on the platform, copies all required files into a temporary local package and updates modInfo with dependencies and tags. Returns the platform operation result. On file-copy failure the method logs the error and performs Cleanup() before returning a failed result. Side effects: creates temporary assets (m_WIPAssets), may run VT processing and pack thumbnail atlas if requested. }} -
public async Task<IModsUploadSupport.ModOperationResult> FinalizeSubmit()
{{ Publishes the WIP (or updates existing published mod depending on updateExisting). Calls Cleanup() afterwards. Returns the platform operation result. }} -
public void ShowModsUIProfilePage()
{{ Opens the platform mods UI profile page and subscribes to onModsUIClosed to refresh social profile when the UI is closed. }} -
private void OnModsUIClosed()
{{ Handler that unsubscribes and triggers RefreshSocialProfile(). }} -
private async void RefreshSocialProfile()
{{ Async method that fetches the social profile from the platform and invokes onSocialProfileSynced on the main thread once fetched. }} -
public void ExcludeSourceTextures(IEnumerable<SurfaceAsset> surfaces, ILocalAssetDatabase database)
{{ For a set of surface assets, determines which TextureAssets are referenced by VT materials vs non-VT materials. Deletes source textures that are exclusively referenced by VT materials, logs conflicts and details for textures referenced by both. Used after generating VT content to avoid shipping duplicate source textures. }} -
private (bool, string) CopyFiles(HashSet<IModsUploadSupport.ModInfo.ModDependency> externalReferences)
{{ Internal method that: - Ensures content folder exists.
- Copies all assets (primary + additional) into a transient local asset DB and tracks created assets.
- Optionally runs VT processing and mid-mip cache building (processVT >= 0) and calls ExcludeSourceTextures.
- Optionally builds a thumbnails atlas.
- Creates a ParadoxMods package asset in the ParadoxMods database and records it in m_WIPAssets.
-
Copies preview and screenshot metadata files into the metadata folder. Returns (true, null) on success or (false, errorMessage) on failure. }}
-
public async Task Cleanup()
{{ Deletes all temporary package assets created (m_WIPAssets) from the ParadoxMods database and unregisters the WIP on the platform (calls UnregisterWIP). Clears internal WIP tracking. Should be called after failed or completed upload flows to avoid leaving junk assets. }} -
public async Task SyncPlatformData()
{{ Asynchronously retrieves: - list of mods by the current author (filtered by typeTags),
- platform tags and DLC tags,
-
social profile. When tasks complete, updates authorMods, availableTags, availableDLCs, socialProfile and attempts to derive tags/typeTags from the mainAsset on the main thread. }}
-
public async Task<IModsUploadSupport.ModInfo> GetExistingInfo()
{{ Fetches detailed ModInfo for the current modInfo from the platform (helper wrapper). }} -
public async Task<(bool, IModsUploadSupport.ModLocalData)> GetLocalData(int id)
{{ Fetches local data for a mod id from the platform. If the local data source in the game's ParadoxMods database is a ParadoxModsDataSource, asks it to populate metadata for the returned localData path. Returns (success, localData). }} -
private void CopyPreview(Dictionary<AssetData, string> processed)
{{ Copies the selected preview asset into the package metadata and stores the filename into modInfo.m_ThumbnailFilename. Uses CopyMetadata under the hood. }} -
private string CopyMetadata(AssetData asset, string name, Dictionary<AssetData, string> processed)
{{ Copies a single metadata image (preview/screenshot) into the metadata folder. Uses a transient local DB to prepare the image via AssetUploadUtils.CopyPreviewImage then writes the image file to the Package metadata path. Returns the filename written or null on error. Updates processed dictionary for deduping. }} -
public void AddScreenshot(AssetData asset)
{{ Adds a screenshot asset to the internal screenshots list. }} -
public void RemoveScreenshot(AssetData asset)
{{ Removes a screenshot asset from the internal screenshots list. }} -
public void ClearScreenshots()
{{ Clears the internal screenshots list. }} -
public void SetPreview(AssetData asset)
{{ Sets the preview asset used for the upload. }} -
private void CopyScreenshot(AssetData asset, int index, Dictionary<AssetData, string> processed)
{{ Copies a screenshot to metadata and appends the filename to modInfo.m_ScreenshotFileNames if not already present. }} -
public void SetPreviewsFromExisting(IModsUploadSupport.ModLocalData localData)
{{ Given a ModLocalData object (from GetLocalData), locates and sets the preview and screenshot assets from the ParadoxMods package on disk (by path). Clears existing screenshots and replaces them. }} -
public void AddAdditionalAsset(AssetData asset)
{{ Adds an additional asset into the package and rebuilds dependency cache. }} -
public void RemoveAdditionalAsset(AssetData asset)
{{ Removes an additional asset and rebuilds dependency cache. }} -
private bool FindByPath(ImageAsset candidate, string imagePath)
{{ Helper to compare an ImageAsset's meta.path to a full filesystem path (case-insensitive). Used when finding preview/screenshot assets from existing local packages. }} -
private static (HashSet<string>, HashSet<string>) GetTags(AssetData asset, HashSet<string> validTags)
{{ Static helper that collects tags and type tags from a single asset using ModTags.GetTags. Returns tuple (typeTags, tags). }} -
private void InitializePreviews()
{{ Populates preview and screenshots with either the found preview for mainAsset, or falls back to MenuHelpers.defaultPreview. Also collects unique previews from all assets and stores them in m_OriginalPreviews and m_Screenshots initial list. }} -
private void InitializeContentPrerequisite()
{{ Scans assets for MapMetadata or SaveGameMetadata and collects contentPrerequisites into modInfo.m_DLCDependencies so platform can be informed of required DLC/content. }} -
private string GetFilename(AssetData asset)
{{ Returns the filename (meta.fileName + meta.extension) for an asset's metadata file, used when writing preview/screenshot files. }} -
public void AddAdditionalTag(string tag)
{{ Adds a user-defined additional tag. }} -
public void RemoveAdditionalTag(string tag)
{{ Removes a user-defined additional tag. }} -
private string[] CollectTags()
{{ Merges the selected platform tags and additionalTags into a unique string array for storing in modInfo.m_Tags. }} -
private string GetMetadataPath()
{{ Returns the relative metadata path under modInfo.m_RootPath (modInfo.kMetadataDirectory). }} -
private string GetContentPath()
{{ Returns the relative content path under modInfo.m_RootPath (modInfo.kContentDirectory). }} -
public string GetAbsoluteContentPath()
{{ Returns the absolute content path by combining the platform mods root path with GetContentPath(). }} -
private string GetAbsoluteMetadataPath()
{{ Returns the absolute metadata path by combining the platform mods root path with GetMetadataPath(). }} -
private void RebuildDependencyCache()
{{ Recomputes m_CachedAssetDependencies by collecting dependencies for prefab assets (via AssetUploadUtils.CollectPrefabAssetDependencies) and adds every asset. Sets hasPrefabAssets flag and updates content prerequisites. Should be called whenever assets/additional assets change. }}
Usage Example
// Simple example showing typical usage from an async UI handler:
async Task UploadAssetExample(AssetData mainAsset, IEnumerable<AssetData> extraAssets)
{
var uploadHandle = new PdxAssetUploadHandle(mainAsset, extraAssets.ToArray());
// Optional: configure metadata
uploadHandle.AddAdditionalTag("MyCustomTag");
uploadHandle.packThumbnailsAtlas = true;
uploadHandle.processVT = -1; // skip VT conversion, or set >=0 to process
// Ensure platform data is up to date (tags, social profile, author mods)
await uploadHandle.SyncPlatformData();
// Begin submit: registers WIP and copies files into a temporary package
var beginResult = await uploadHandle.BeginSubmit();
if (!beginResult.m_Success)
{
Debug.LogError("BeginSubmit failed: " + beginResult.m_Error?.m_Details);
return;
}
// Finalize submit: publishes or updates the mod on Paradox Mods
var finalizeResult = await uploadHandle.FinalizeSubmit();
if (!finalizeResult.m_Success)
{
Debug.LogError("FinalizeSubmit failed: " + finalizeResult.m_Error?.m_Details);
}
else
{
Debug.Log("Upload published successfully.");
}
// Cleanup is called by FinalizeSubmit(); you can also call it explicitly on failure/abort.
}
{{ Notes: - Many methods interact with Unity/main-thread objects; UI or GameManager.instance.RunOnMainThread should be used if calling from background threads. - BeginSubmit and FinalizeSubmit are asynchronous and involve network/platform calls; ensure proper error handling and user feedback in UI code. - Temporary assets created in the ParadoxMods DB are tracked in m_WIPAssets and removed during Cleanup(). }}