Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/PushkinStudio/PsData
Flexible data model plugin for Unreal Engine 4
https://github.com/PushkinStudio/PsData
cpp14 datamodel magic ue4 ue4-plugin unreal-engine unreal-engine-4
Last synced: 15 days ago
JSON representation
Flexible data model plugin for Unreal Engine 4
- Host: GitHub
- URL: https://github.com/PushkinStudio/PsData
- Owner: PushkinStudio
- License: mit
- Created: 2018-09-12T09:34:26.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-20T13:01:42.000Z (almost 2 years ago)
- Last Synced: 2024-07-30T20:58:30.861Z (3 months ago)
- Topics: cpp14, datamodel, magic, ue4, ue4-plugin, unreal-engine, unreal-engine-4
- Language: C++
- Size: 884 KB
- Stars: 40
- Watchers: 17
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome_unreal_engine_4_-_5 - Data Model (Cpp)
- awesome_unreal_engine_4_-_5 - Data Model (Cpp)
README
# PsData
Flexible data model plugin for Unreal Engine 4
## Examples
Define PsData classes:
```cpp
// Assume that you project called 'Foo'#include "PsDataAPI.h"
// Enum
UENUM(BlueprintType)
enum class EFooDamageType : uint8
{
None = 0,
Pure = 1,
Physical = 2,
Psi = 3,
Pierce = 4
};
DESCRIBE_ENUM(EFooDamageType);// Character data class
UCLASS()
class UFooCharacterData : public UPsData
{
GENERATED_BODY()/** Weapon damage type */
DPROP(EFooDamageType, DamageType);/** Current health value */
/** DMETA(Event) means that this property can fire events when it will changed */
DMETA(Event)
DPROP(int32, Health);/** Equipmented weapon */
/** This is property with other PsData class type */
DPROP(UFooWeaponData*, EquipmentedWeapon);/** Current location on the battlefield */
/** DMETA(Strict) means that this property was be constructed by default and cannot be null or be reset */
DMETA(Strict)
DPROP(UFooPointData*, Location);/** Abilities */
/** This is array property */
DARRAY(UFooBattleAbilityData*, BattleAbilities);/** Link to the character prototype */
DPROP(FString, CharacterProtoId);
DLINK(UFooCharacterProtoData, CharacterProtoId, Prototypes.Characters);/** Link to the current battle target */
/** DMETA(Nullable) means that this link can be null */
DPROP(FString, TargetId);
DMETA(Nullable)
DLINK(UFooCharacterData, TargetId, Game.Battle.Characters);protected:
/** Some kind of constructor */
void InitProperties() override
{
SetDamageType(EFooDamageType::Physical);
}
};UCLASS()
class UFooPointData : public UPsData
{
GENERATED_BODY()DMETA(Event, Bubbles)
DPROP(int32, X);DMETA(Event, Bubbles)
DPROP(int32, Y);public:
FIntPoint GetIntPoint() const
{
return FIntPoint{GetX(), GetY()};
}
};
```Root of the model:
```cpp
// Root of the data modelUCLASS(Blueprintable, BlueprintType)
class UFooRootData : public UPsData
{
/** Game state */
DMETA(Strict)
DPROP(UFooGameData*, Game);/** Static world data */
DMETA(Strict)
DPROP_CONST(UFooPrototypesData*, Prototypes, FFooPrototypesDataAccessor);
};////////////////////////////////////////////////////////
// Accessors for mutation of root data const membersclass FFooPrototypesDataAccessor
{
private:
// Only classes that need modifying static world data
friend UFooDataController;static UFooPrototypesData* GetMutablePrototypes(UFooRootData* RootData)
{
return RootData->GetMutablePrototypes();
}
};
```Work with the model:
```cpp
void UFooDataController::Init()
{
// Create root node
RootData = NewObject();// Get pointer to the mutable data
auto PrototypesData = FFooPrototypesDataAccessor::GetMutablePrototypes(RootData);// Deserialize from UDataTable asset PrototypesDataTableAsset
auto Deserializer = FPsDataTableDeserializer(PrototypesDataTableAsset, PrototypesData->GetCharacters());
PrototypesData->DataDeserialize(&Deserializer);auto Characters = PrototypesData->GetCharacters();
for (auto const Proto : Characters) {
auto GameCharacter = NewObject();
GameCharacter->SetCharacterProtoId(Proto->GetDataKey());
// Setup character...// Add into the game state
RootData->GetGame()->GetCharacters().Add(GameCharacter);
}
//...
}
```