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 NativeModuleMetadata
40{
41 bool mHasNative = false; // Whether addon has native code
42 NativeAddonTarget mTarget = NativeAddonTarget::EngineAndEditor; // Where code runs
43 std::string mSourceDir = "Source"; // Relative path to source directory
44 std::string mBinaryName; // Output binary name (without extension)
45 std::string mEntrySymbol = "PolyphasePlugin_GetDesc";
46 std::string mExportDefine; // Optional custom export macro (e.g., "INVENTORY_RUNTIME_EXPORTS")
47 uint32_t mPluginApiVersion = 1;
48 std::vector<std::string> mDependencies; // IDs of other native addons this depends on
49 NativeAddonResolveMode mResolveMode = NativeAddonResolveMode::Source;
50 std::vector<NativeBinaryDescriptor> mBinaries;
51
52 // Optional extras for addons that bundle third-party libraries (e.g. FFmpeg).
53 // All relative paths resolve against the addon's package root (folder containing package.json).
54 // These are the COMMON arrays applied to every platform; per-platform overrides
55 // (mPerPlatform) are concatenated on top by ResolveExtras().
56 std::vector<std::string> mExtraDefines; // e.g. ["POLYPHASE_WITH_FFMPEG=1"]
57 std::vector<std::string> mExtraIncludeDirs; // e.g. ["External/ffmpeg/include"]
58 std::vector<std::string> mExtraLibDirs; // e.g. ["External/ffmpeg/lib"]
59 std::vector<std::string> mExtraLibs; // e.g. ["avformat.lib", "avcodec.lib", ...]
60 std::vector<std::string> mCopyBinaries; // Dirs whose contents get copied next to the addon DLL post-build (e.g. ["External/ffmpeg/bin"])
61
62 // Per-platform extras. Same shape as the common arrays above; merged
63 // (concatenated, common-first) by ResolveExtras() when generating the build
64 // command for a specific target. Keys are GetPlatformString(Platform) values:
65 // "Windows", "Linux", "Android", "GameCube", "Wii", "3DS". Missing keys mean
66 // "no overrides for that platform". Lets PC-only deps (e.g. FFmpeg) live
67 // under nativePerPlatform.Windows so console builds don't try to link them.
68 struct PlatformExtras
69 {
70 std::vector<std::string> mExtraDefines;
71 std::vector<std::string> mExtraIncludeDirs;
72 std::vector<std::string> mExtraLibDirs;
73 std::vector<std::string> mExtraLibs;
74 std::vector<std::string> mCopyBinaries;
75 };
76 std::unordered_map<std::string, PlatformExtras> mPerPlatform;
77
78 // Returns the effective extras for a given platform: common arrays first,
79 // then mPerPlatform[platformName] appended (if present). Pass an empty string
80 // to get just the common arrays.
81 PlatformExtras ResolveExtras(const std::string& platformName) const
82 {
83 PlatformExtras out;
84 out.mExtraDefines = mExtraDefines;
85 out.mExtraIncludeDirs = mExtraIncludeDirs;
86 out.mExtraLibDirs = mExtraLibDirs;
87 out.mExtraLibs = mExtraLibs;
88 out.mCopyBinaries = mCopyBinaries;
89
90 if (!platformName.empty())
91 {
92 auto it = mPerPlatform.find(platformName);
93 if (it != mPerPlatform.end())
94 {
95 const PlatformExtras& over = it->second;
96 out.mExtraDefines.insert (out.mExtraDefines.end(), over.mExtraDefines.begin(), over.mExtraDefines.end());
97 out.mExtraIncludeDirs.insert(out.mExtraIncludeDirs.end(), over.mExtraIncludeDirs.begin(), over.mExtraIncludeDirs.end());
98 out.mExtraLibDirs.insert (out.mExtraLibDirs.end(), over.mExtraLibDirs.begin(), over.mExtraLibDirs.end());
99 out.mExtraLibs.insert (out.mExtraLibs.end(), over.mExtraLibs.begin(), over.mExtraLibs.end());
100 out.mCopyBinaries.insert (out.mCopyBinaries.end(), over.mCopyBinaries.begin(), over.mCopyBinaries.end());
101 }
102 }
103 return out;
104 }
105};
106
110struct ContentMetadata
111{
112 std::string mId; // Unique ID (directory name)
113 std::string mName;
114 std::string mAuthor;
115 std::string mDescription;
116 std::string mUrl; // Source URL (GitHub, etc.)
117 std::string mVersion;
118 std::string mUpdated; // ISO date string
119 std::vector<std::string> mTags;
120 bool mIsCpp = false; // C++ or Lua (templates only)
121};
122
126struct Template
127{
128 ContentMetadata mMetadata;
129 std::string mPath; // Full path to template directory
130 bool mHasThumbnail = false;
131};
132
136struct Addon
137{
138 ContentMetadata mMetadata;
139 std::string mRepoUrl; // Repository URL this addon came from
140 bool mHasThumbnail = false;
141 bool mIsInstalled = false;
142 bool mIsMain = true;
143 bool mIsStandalone = false; // Addon is entire repo, not a subdirectory
144 std::string mInstalledVersion;
145 NativeModuleMetadata mNative; // Native module configuration
146};
147
151struct AddonRepository
152{
153 std::string mName;
154 std::string mUrl; // Base URL (GitHub repo URL)
155 std::vector<std::string> mAddonIds; // List of addon IDs in this repo
156};
157
161struct InstalledAddon
162{
163 std::string mId;
164 std::string mVersion;
165 std::string mInstalledDate; // ISO date string
166 std::string mRepoUrl;
167 bool mEnabled = true; // Whether addon is enabled
168 bool mEnableNative = true; // Whether native code should be loaded
169 NativeAddonResolveMode mNativeMode = NativeAddonResolveMode::Source;
170 std::string mLastSyncAt;
171 std::string mLastSyncSource;
172 std::string mLastSyncStatus;
173};
174
175#endif