Giter Club home page Giter Club logo

psdata's Introduction

PsData

Flexible data model plugin for Unreal Engine 4

Examples

Define PsData classes:

// 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:

// Root of the data model

UCLASS(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 members

class FFooPrototypesDataAccessor
{
private:
    // Only classes that need modifying static world data
    friend UFooDataController;

    static UFooPrototypesData* GetMutablePrototypes(UFooRootData* RootData)
    {
        return RootData->GetMutablePrototypes();
    }
};

Work with the model:

void UFooDataController::Init()
{
    // Create root node
    RootData = NewObject<UFooRootData>();

    // 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<UFooCharacterData>();
        GameCharacter->SetCharacterProtoId(Proto->GetDataKey());
        // Setup character...

        // Add into the game state
        RootData->GetGame()->GetCharacters().Add(GameCharacter);
    }
    //...
}

psdata's People

Contributors

nprudnikov avatar ufna avatar antonrr avatar varlog avatar ilinaleksey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.