Skip to content

Commit

Permalink
more blo stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Astral-C committed Dec 24, 2024
1 parent 1eeca31 commit 6f997d2
Show file tree
Hide file tree
Showing 12 changed files with 839 additions and 89 deletions.
2 changes: 1 addition & 1 deletion include/DOM/DOMNodeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class LDOMNodeBase : public std::enable_shared_from_this<LDOMNodeBase>

void RemoveChild(std::shared_ptr<LDOMNodeBase> child)
{
ptrdiff_t index = LGenUtility::VectorIndexOf(Children, child);
std::ptrdiff_t index = LGenUtility::VectorIndexOf(Children, child);
if (index == -1)
return;

Expand Down
8 changes: 4 additions & 4 deletions include/GenUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace LGenUtility
extern std::fstream Log;
// Returns the index of the given element in the given vector, or -1 if the element is not in that vector.
template<typename T>
ptrdiff_t VectorIndexOf(const std::vector<T>& vec, const T& elem)
std::ptrdiff_t VectorIndexOf(const std::vector<T>& vec, const T& elem)
{
ptrdiff_t result = -1;
std::ptrdiff_t result = -1;

auto it = std::find(vec.begin(), vec.end(), elem);
if (it != vec.end())
Expand All @@ -26,14 +26,14 @@ namespace LGenUtility

// Returns whether the given element is contained in the given vector.
template<typename T>
ptrdiff_t VectorContains(const std::vector<T>& vec, const T& elem)
std::ptrdiff_t VectorContains(const std::vector<T>& vec, const T& elem)
{
return VectorIndexOf(vec, elem) != -1;
}

// Returns whether the given element is contained in the given vector, with the index parameter set to the element's position.
template<typename T>
ptrdiff_t VectorContains(const std::vector<T>& vec, const T& elem, ptrdiff_t& index)
std::ptrdiff_t VectorContains(const std::vector<T>& vec, const T& elem, std::ptrdiff_t& index)
{
index = VectorIndexOf(vec, elem);
return index != -1;
Expand Down
51 changes: 40 additions & 11 deletions include/io/BloIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <glm/glm.hpp>

namespace Blo {
enum class ResourceType : uint32_t {
enum class ResourceType : uint8_t {
None,
Unknown,
Directory,
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace Blo {
Bottom = (1 << 0),
Top = (1 << 1),
Right = (1 << 2),
Left = (1 << 3)
Left = (1 << 3),
};

enum class Anchor : uint32_t {
Expand All @@ -69,9 +69,10 @@ namespace Blo {
};

struct Resource {
ResourceType mType;
uint8_t mType;
std::string mPath;
virtual void Load(bStream::CStream* stream, std::shared_ptr<Archive::Folder> timg);
void Save(bStream::CStream* stream);
};

struct Image : Resource {
Expand Down Expand Up @@ -99,49 +100,61 @@ namespace Blo {
protected:
ElementType mType;
std::shared_ptr<Pane> mParent;
std::vector<std::shared_ptr<Pane>> mChildren;
uint32_t mID;
bool mVisible;
uint8_t mCullMode;
Anchor mAnchor;
uint8_t mAnchor;
float mAngle;
bool mInheritAlpha;
bool mConnectParent;

uint8_t mAccumulateAlpha;
std::map<std::string, bool> mPaneArgs;

public:
uint32_t mID;
int16_t mRect[4] {32, 32, 100, 100};
uint8_t mAlpha;
ElementType Type() { return mType; }
int16_t mRect[4];
std::vector<std::shared_ptr<Pane>> mChildren;
virtual bool Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::shared_ptr<Archive::Folder> timg);
virtual void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
virtual void Draw(std::shared_ptr<Blo::Pane>& selection);
virtual void Save(bStream::CStream* stream);

Pane();
Pane(ElementType t, uint32_t id);
};

class Picture : public Pane {
std::shared_ptr<Image> mTextures[4] { nullptr, nullptr, nullptr, nullptr };
Palette mPalette;
Binding mBinding;
uint8_t mBinding;
double mBlendFactors[4];
double mBlendAlphaFactors[4];
int mTextureCount;

WrapMode mWrapX;
WrapMode mWrapY;
uint8_t mWrapX;
uint8_t mWrapY;
uint8_t mMirror;
bool mRotate;

glm::vec4 mFromColor;
glm::vec4 mToColor;

glm::vec4 mColors[4];
std::map<std::string, bool> mPictArgs;

public:
std::shared_ptr<Image> GetTexture(){ return mTextures[0]; }
bool Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::shared_ptr<Archive::Folder> timg);
void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
void Draw(std::shared_ptr<Blo::Pane>& selection);
void Save(bStream::CStream* stream);

void SetWidth(uint16_t w) { mRect[2] = w; }
void SetHeight(uint16_t h) { mRect[3] = h; }

Picture();
};

class Window : public Pane {
Expand All @@ -153,15 +166,22 @@ namespace Blo {
int16_t mContentRect[4];
glm::vec4 mFromColor;
glm::vec4 mToColor;
std::map<std::string, bool> mWindowArgs;
public:
bool Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::shared_ptr<Archive::Folder> timg);
void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
void Draw(std::shared_ptr<Blo::Pane>& selection);
void Save(bStream::CStream* stream);

std::shared_ptr<Image> GetTexture(uint32_t id) { if(id < 4) { return mTextures[id]; } else { return nullptr; } }
void SetTexture(std::shared_ptr<Image> img, uint32_t id) { if(id < 4) { mTextures[id] = img; } }

Window();
};

class Textbox : public Pane {
Font mFont;
glm::vec4 mTopColor, mBottomColor;
glm::vec4 mTopColor {1.0f, 1.0f, 1.0f, 1.0f}, mBottomColor {1.0f, 1.0f, 1.0f, 1.0f};
uint8_t mHAlign, mVAlign;

uint16_t mFontSpacing;
Expand All @@ -173,10 +193,17 @@ namespace Blo {

glm::vec4 mFromColor;
glm::vec4 mToColor;
std::map<std::string, bool> mTextboxArgs;
public:
bool Load(bStream::CStream* stream, std::shared_ptr<Pane> parent, std::shared_ptr<Archive::Folder> timg);
void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
void Draw(std::shared_ptr<Blo::Pane>& selection);
void Save(bStream::CStream* stream);

Font* GetFont() { return &mFont; };
std::string* GetText() { return &mText; }

Textbox();
};

class Screen : public Pane {
Expand All @@ -187,6 +214,8 @@ namespace Blo {
bool Load(bStream::CStream* stream, std::shared_ptr<Archive::Folder> timg);
void DrawHierarchy(std::shared_ptr<Blo::Pane>& selection);
void Draw(std::shared_ptr<Blo::Pane>& selection);

Screen();
};

};
1 change: 1 addition & 0 deletions include/io/BtiIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Bti {

uint8_t* Load(bStream::CStream* stream);
void Save(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
void SetFormat(uint8_t fmt) { mFormat = fmt; }

Bti(){}
~Bti(){ if(mImageData != nullptr){ delete[] mImageData; } }
Expand Down
2 changes: 1 addition & 1 deletion src/DOM/CharacterDOMNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void LCharacterDOMNode::PreProcess()
auto itemAppearNodes = mapNodeLocked->GetChildrenOfType<LItemAppearDOMNode>(EDOMNodeType::ItemAppear);

auto lockedItemRef = mItemTableRef.lock();
ptrdiff_t index = LGenUtility::VectorIndexOf(itemAppearNodes, lockedItemRef);
std::ptrdiff_t index = LGenUtility::VectorIndexOf(itemAppearNodes, lockedItemRef);

if (index == -1)
mItemTableIndex = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/DOM/EnemyDOMNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void LEnemyDOMNode::PreProcess()
auto furnitureNodes = parentShared->GetChildrenOfType<LFurnitureDOMNode>(EDOMNodeType::Furniture);

// Grab the index of the furniture node in the list of furniture. Report an error if it doesn't exist, because that shouldn't happen.
ptrdiff_t furnitureIndex = LGenUtility::VectorIndexOf(furnitureNodes, furnitureShared);
std::ptrdiff_t furnitureIndex = LGenUtility::VectorIndexOf(furnitureNodes, furnitureShared);
if (furnitureIndex == -1)
{
LGenUtility::Log << "[EnemyDOMNode]: Tried to set furniture access name to nonexistent furniture node!";
Expand Down Expand Up @@ -284,7 +284,7 @@ void LEnemyDOMNode::PreProcess()
auto itemAppearNodes = mapNodeLocked->GetChildrenOfType<LItemAppearDOMNode>(EDOMNodeType::ItemAppear);

auto lockedItemRef = mItemTableRef.lock();
ptrdiff_t index = LGenUtility::VectorIndexOf(itemAppearNodes, lockedItemRef);
std::ptrdiff_t index = LGenUtility::VectorIndexOf(itemAppearNodes, lockedItemRef);

if (index == -1)
mItemTableIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/DOM/FurnitureDOMNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void LFurnitureDOMNode::PreProcess()
auto itemAppearNodes = mapNodeLocked->GetChildrenOfType<LItemAppearDOMNode>(EDOMNodeType::ItemAppear);

auto lockedItemRef = mItemTableRef.lock();
ptrdiff_t index = LGenUtility::VectorIndexOf(itemAppearNodes, lockedItemRef);
std::ptrdiff_t index = LGenUtility::VectorIndexOf(itemAppearNodes, lockedItemRef);

if (index == -1)
mItemTableIndex = 0;
Expand Down
1 change: 1 addition & 0 deletions src/DOM/RoomDOMNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ void LRoomDOMNode::RenderDetailsUI(float dt)

std::vector<uint8_t> imgData(x*y*n);
std::memcpy(imgData.data(), img, x*y*n);
stbi_image_free(img);

auto fileData = GCResourceManager.mGameArchive->GetFile(std::format("/kawano/roomname/{}", LResUtility::GetNameMap("MapTitlecards")["titlecards"][mRoomNumber].get<std::string>()));
bStream::CMemoryStream file(0x20 + (x * y), bStream::Endianess::Big, bStream::OpenMode::Out);
Expand Down
Loading

0 comments on commit 6f997d2

Please sign in to comment.