summaryrefslogblamecommitdiffstats
path: root/src/Block.cpp
blob: 8af5a4b1fe70b50401bbb5ff7fa0d28334e6518f (plain) (tree)
1
2
3
4
5
6
7
8
9

                    

              

                                             
 

                                              

                                                                    






                                                                                                        

 
                                          






                                                            
 
#include "Block.hpp"

#include <map>

static std::map<BlockId, BlockInfo> blocks;
static std::map<BlockId, LiquidInfo> liquids;

static BlockInfo UnknownBlock{ true, "", "" };
static LiquidInfo UnknownLiquid{ "", "" };

void RegisterStaticBlockInfo(BlockId blockId, BlockInfo blockInfo) {
    blocks.emplace(blockId, blockInfo);
}

void RegisterStaticLiquidInfo(BlockId blockId, LiquidInfo liquidInfo) {
    liquids[blockId] = liquidInfo;
    for (uint8_t i = 0; i < 16; i++)
        blocks.emplace(BlockId{ blockId.id, i }, BlockInfo{ true, "@liquid", liquidInfo.stillTexture });
}

BlockInfo* GetBlockInfo(BlockId blockId) {
    auto it = blocks.find(blockId);
    return it != blocks.end() ? &it->second : &UnknownBlock;
}

const LiquidInfo& GetBlockLiquidInfo(BlockId blockId) {
    auto it = liquids.find(blockId);
    return it != liquids.end() ? it->second : UnknownLiquid;
}