Polyphase Game Engine
Loading...
Searching...
No Matches
TemplateData.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <string>
6#include <vector>
7#include <unordered_map>
8#include <stdint.h>
9
13enum class NativeAddonTarget
14{
15 EditorOnly, // Only loads in editor, NOT compiled into final builds
16 EngineAndEditor // Loads in editor AND compiled into final builds
17};
18
19enum class NativeAddonResolveMode
20{
21 Source,
22 Binary
23};
24
25struct NativeBinaryDescriptor
26{
27 std::string mPlatform;
28 std::string mArch;
29 std::string mConfig;
30 std::string mType; // releaseAsset | url | zip
31 std::string mValue; // asset name or URL
32 std::string mChecksumSha256; // optional
33 std::string mEntryPath; // optional (zip extraction)
34};
35
39struct AddonDependencySpec
40{
41 enum Kind
42 {
43 Registry, // Resolve via configured AddonManager repos
44 GitHubRepo, // URL is a GitHub repo; mRef selects branch/tag/commit
45 ZipUrl // URL points directly at a .zip
46 };
47
48 std::string mId; // Addon ID (folder name under Packages/)
49 std::string mUrl; // Source URL (empty for Registry)
50 std::string mRef; // GitHub ref (branch/tag/commit); empty = default branch
51 Kind mKind = Registry;
52
53 // Build a spec from "id" and "<url>[#ref]" / "" (registry lookup).
54 // Classification:
55 // - empty / no "://" -> Registry
56 // - ends in ".zip" -> ZipUrl
57 // - contains "github.com" -> GitHubRepo (ref split on '#')
58 // - other URL -> ZipUrl (assume direct download)
59 static AddonDependencySpec FromValue(const std::string& id, const std::string& value)
60 {
61 AddonDependencySpec out;
62 out.mId = id;
63 if (value.empty() || value.find("://") == std::string::npos)
64 {
65 out.mKind = Registry;
66 out.mUrl = value;
67 return out;
68 }
69
70 std::string url = value;
71 size_t hashPos = url.find('#');
72 if (hashPos != std::string::npos)
73 {
74 out.mRef = url.substr(hashPos + 1);
75 url = url.substr(0, hashPos);
76 }
77 out.mUrl = url;
78
79 std::string lower = url;
80 for (char& c : lower) c = (char)((c >= 'A' && c <= 'Z') ? c + 32 : c);
81 if (lower.size() >= 4 && lower.compare(lower.size() - 4, 4, ".zip") == 0)
82 {
83 out.mKind = ZipUrl;
84 }
85 else if (lower.find("github.com/") != std::string::npos)
86 {
87 out.mKind = GitHubRepo;
88 }
89 else
90 {
91 out.mKind = ZipUrl;
92 }
93 return out;
94 }
95};
96
100struct NativeModuleMetadata
101{
102 bool mHasNative = false; // Whether addon has native code
103 NativeAddonTarget mTarget = NativeAddonTarget::EngineAndEditor; // Where code runs
104 std::string mSourceDir = "Source"; // Relative path to source directory
105 std::string mBinaryName; // Output binary name (without extension)
106 std::string mEntrySymbol = "PolyphasePlugin_GetDesc";
107 std::string mExportDefine; // Optional custom export macro (e.g., "INVENTORY_RUNTIME_EXPORTS")
108 uint32_t mPluginApiVersion = 1;
109 NativeAddonResolveMode mResolveMode = NativeAddonResolveMode::Source;
110 std::vector<NativeBinaryDescriptor> mBinaries;
111
112 // Optional extras for addons that bundle third-party libraries (e.g. FFmpeg).
113 // All relative paths resolve against the addon's package root (folder containing package.json).
114 // These are the COMMON arrays applied to every platform; per-platform overrides
115 // (mPerPlatform) are concatenated on top by ResolveExtras().
116 std::vector<std::string> mExtraDefines; // e.g. ["POLYPHASE_WITH_FFMPEG=1"]
117 std::vector<std::string> mExtraIncludeDirs; // e.g. ["External/ffmpeg/include"]
118 std::vector<std::string> mExtraLibDirs; // e.g. ["External/ffmpeg/lib"]
119 std::vector<std::string> mExtraLibs; // e.g. ["avformat.lib", "avcodec.lib", ...]
120 std::vector<std::string> mCopyBinaries; // Dirs whose contents get copied next to the addon DLL post-build (e.g. ["External/ffmpeg/bin"])
121
122 // Per-platform extras. Same shape as the common arrays above; merged
123 // (concatenated, common-first) by ResolveExtras() when generating the build
124 // command for a specific target. Keys are GetPlatformString(Platform) values:
125 // "Windows", "Linux", "Android", "GameCube", "Wii", "3DS". Missing keys mean
126 // "no overrides for that platform". Lets PC-only deps (e.g. FFmpeg) live
127 // under nativePerPlatform.Windows so console builds don't try to link them.
128 struct PlatformExtras
129 {
130 std::vector<std::string> mExtraDefines;
131 std::vector<std::string> mExtraIncludeDirs;
132 std::vector<std::string> mExtraLibDirs;
133 std::vector<std::string> mExtraLibs;
134 std::vector<std::string> mCopyBinaries;
135 };
136 std::unordered_map<std::string, PlatformExtras> mPerPlatform;
137
148 struct BuildTargetMetadata
149 {
150 std::string mId; // Reverse-DNS id, e.g. "homebrew.dreamcast"
151 std::string mDisplayName; // Human label, e.g. "Dreamcast (KallistiOS)"
152 std::string mCategory; // UI grouping, e.g. "Retro Consoles"
153 };
154 std::vector<BuildTargetMetadata> mBuildTargets;
155
156 // Returns the effective extras for a given platform: common arrays first,
157 // then mPerPlatform[platformName] appended (if present). Pass an empty string
158 // to get just the common arrays.
159 PlatformExtras ResolveExtras(const std::string& platformName) const
160 {
161 PlatformExtras out;
162 out.mExtraDefines = mExtraDefines;
163 out.mExtraIncludeDirs = mExtraIncludeDirs;
164 out.mExtraLibDirs = mExtraLibDirs;
165 out.mExtraLibs = mExtraLibs;
166 out.mCopyBinaries = mCopyBinaries;
167
168 if (!platformName.empty())
169 {
170 auto it = mPerPlatform.find(platformName);
171 if (it != mPerPlatform.end())
172 {
173 const PlatformExtras& over = it->second;
174 out.mExtraDefines.insert (out.mExtraDefines.end(), over.mExtraDefines.begin(), over.mExtraDefines.end());
175 out.mExtraIncludeDirs.insert(out.mExtraIncludeDirs.end(), over.mExtraIncludeDirs.begin(), over.mExtraIncludeDirs.end());
176 out.mExtraLibDirs.insert (out.mExtraLibDirs.end(), over.mExtraLibDirs.begin(), over.mExtraLibDirs.end());
177 out.mExtraLibs.insert (out.mExtraLibs.end(), over.mExtraLibs.begin(), over.mExtraLibs.end());
178 out.mCopyBinaries.insert (out.mCopyBinaries.end(), over.mCopyBinaries.begin(), over.mCopyBinaries.end());
179 }
180 }
181 return out;
182 }
183};
184
188struct ContentMetadata
189{
190 std::string mId; // Unique ID (directory name)
191 std::string mName;
192 std::string mAuthor;
193 std::string mDescription;
194 std::string mUrl; // Source URL (GitHub, etc.)
195 std::string mVersion;
196 std::string mUpdated; // ISO date string
197 std::vector<std::string> mTags;
198 bool mIsCpp = false; // C++ or Lua (templates only)
199
200 // Cross-addon dependencies, parsed from top-level "dependencies" in package.json
201 // (works for both native and non-native addons).
202 std::vector<AddonDependencySpec> mDependencies;
203
204 // Relative path (from addon root) to a shell script run after install/dep-resolution.
205 // Invoked as: bash <addonDir>/<mOnInstallScript> <platform> <addonDir>
206 std::string mOnInstallScript;
207};
208
212struct Template
213{
214 ContentMetadata mMetadata;
215 std::string mPath; // Full path to template directory
216 bool mHasThumbnail = false;
217};
218
222struct Addon
223{
224 ContentMetadata mMetadata;
225 std::string mRepoUrl; // Repository URL this addon came from
226 bool mHasThumbnail = false;
227 bool mIsInstalled = false;
228 bool mIsMain = true;
229 bool mIsStandalone = false; // Addon is entire repo, not a subdirectory
230 std::string mInstalledVersion;
231 NativeModuleMetadata mNative; // Native module configuration
232};
233
237struct AddonRepository
238{
239 std::string mName;
240 std::string mUrl; // Base URL (GitHub repo URL)
241 std::vector<std::string> mAddonIds; // List of addon IDs in this repo
242};
243
247struct InstalledAddon
248{
249 std::string mId;
250 std::string mVersion;
251 std::string mInstalledDate; // ISO date string
252 std::string mRepoUrl;
253 bool mEnabled = true; // Whether addon is enabled
254 bool mEnableNative = true; // Whether native code should be loaded
255 NativeAddonResolveMode mNativeMode = NativeAddonResolveMode::Source;
256 std::string mLastSyncAt;
257 std::string mLastSyncSource;
258 std::string mLastSyncStatus;
259 bool mTrustedScripts = false; // User opted into "Always trust this addon" for onInstall scripts
260};
261
262#endif