#include "behavior.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include UF_BEHAVIOR_REGISTER_CPP(ext::CraetureBehavior) UF_BEHAVIOR_TRAITS_CPP(ext::CraetureBehavior, ticks = true, renders = false, multithread = false) #define this (&self) namespace { void load( uf::Object& self, const uf::Image& image ) { auto& graphic = self.getComponent(); auto& texture = graphic.material.textures.emplace_back(); texture.loadFromImage( image ); auto& mesh = self.getComponent(); mesh.bindIndirect(); mesh.bind(); float scaleX = 1; float scaleY = 1; mesh.insertVertices({ { {-1.0f * scaleX, 1.0f * scaleY, 0.0f}, {0.0f, 1.0f}, {}, {0.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, { {-1.0f * scaleX, -1.0f * scaleY, 0.0f}, {0.0f, 0.0f}, {}, {0.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, { {1.0f * scaleX, -1.0f * scaleY, 0.0f}, {1.0f, 0.0f}, {}, {1.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, { {1.0f * scaleX, 1.0f * scaleY, 0.0f}, {1.0f, 1.0f}, {}, {1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, } }); mesh.insertIndices({ 0, 1, 2, 2, 3, 0 }); uf::graph::convert( self ); } } void ext::CraetureBehavior::initialize( uf::Object& self ) { /* this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){ if ( !uf::asset::isExpected( payload, uf::asset::Type::IMAGE ) ) return; if ( !uf::asset::has( payload ) ) uf::asset::load( payload ); const auto& image = uf::asset::get( payload ); ::load( self, image ); }); */ auto& metadata = this->getComponent(); auto& metadataJson = this->getComponent(); UF_BEHAVIOR_METADATA_BIND_SERIALIZER_HOOKS(metadata, metadataJson); } void ext::CraetureBehavior::tick( uf::Object& self ) { auto& metadata = this->getComponent(); if ( this->hasComponent() ) { auto& graph = this->getComponent(); pod::payloads::QueueAnimationPayload payload; payload.name = metadata.animation; this->queueHook("animation:Set.%UID%", payload); metadata.animation = ""; } } void ext::CraetureBehavior::render( uf::Object& self ){} void ext::CraetureBehavior::destroy( uf::Object& self ){} void ext::CraetureBehavior::Metadata::serialize( uf::Object& self, uf::Serializer& serializer ){} void ext::CraetureBehavior::Metadata::deserialize( uf::Object& self, uf::Serializer& serializer ){} #undef this