[Block] 'custom_param_bits' attribute added. Fixed #139.
This commit is contained in:
parent
c96aef94c1
commit
54ffc2c33d
@ -38,6 +38,19 @@ color_multiplier = {1, 1, 1, 1} -- full white, this is the default value
|
||||
|
||||
Only the pure gray parts (red == green == blue) will be affected by this multiplier.
|
||||
|
||||
### `custom_param_bits`
|
||||
|
||||
Allocate a certain number of bits in block param for custom data.
|
||||
|
||||
**Note:** Block param is limited to 16 bits.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
custom_param_bits = 2 -- uses 2 bits
|
||||
```
|
||||
|
||||
Default value is `0`.
|
||||
|
||||
### `draw_offset`
|
||||
|
||||
Draw offset of the block.
|
||||
|
2
external/gamekit
vendored
2
external/gamekit
vendored
@ -1 +1 @@
|
||||
Subproject commit b638de3f61cf00dd5385a806b4ef3eb3bcde0526
|
||||
Subproject commit dae79e1b24e6816397acf37b35fca33433a862ab
|
@ -49,13 +49,13 @@ const TilesDef &Block::tiles(u16 stateID) const {
|
||||
|
||||
void Block::serialize(sf::Packet &packet) const {
|
||||
packet << u32(m_id) << m_stringID << m_canUpdate << m_canBeActivated
|
||||
<< m_isRotatable << m_groups << m_states << m_param;
|
||||
<< m_isRotatable << m_groups << m_states << m_param << m_customParamBits;
|
||||
}
|
||||
|
||||
void Block::deserialize(sf::Packet &packet) {
|
||||
u32 id;
|
||||
packet >> id >> m_stringID >> m_canUpdate >> m_canBeActivated
|
||||
>> m_isRotatable >> m_groups >> m_states >> m_param;
|
||||
>> m_isRotatable >> m_groups >> m_states >> m_param >> m_customParamBits;
|
||||
m_id = id;
|
||||
|
||||
for (auto &it : m_states) {
|
||||
|
@ -80,14 +80,17 @@ class Block : public gk::ISerializable {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const BlockParam ¶m() const { return m_param; }
|
||||
BlockParam ¶m() { return m_param; }
|
||||
|
||||
BlockState &addState();
|
||||
BlockState &getState(u16 id);
|
||||
const BlockState &getState(u16 id) const;
|
||||
const std::deque<BlockState> &states() const { return m_states; }
|
||||
|
||||
const BlockParam ¶m() const { return m_param; }
|
||||
BlockParam ¶m() { return m_param; }
|
||||
|
||||
u8 customParamBits() const { return m_customParamBits; }
|
||||
void setCustomParamBits(u8 customParamBits) { m_customParamBits = customParamBits; }
|
||||
|
||||
static void initUsertype(sol::state &lua);
|
||||
|
||||
protected:
|
||||
@ -107,6 +110,8 @@ class Block : public gk::ISerializable {
|
||||
std::deque<BlockState> m_states;
|
||||
|
||||
BlockParam m_param{*this};
|
||||
|
||||
u8 m_customParamBits = 0;
|
||||
};
|
||||
|
||||
#endif // BLOCK_HPP_
|
||||
|
@ -49,6 +49,7 @@ class BlockParam : public gk::ISerializable {
|
||||
enum Type {
|
||||
Rotation,
|
||||
State,
|
||||
Custom,
|
||||
|
||||
Count
|
||||
};
|
||||
|
@ -44,6 +44,7 @@ void LuaBlockLoader::loadBlock(const sol::table &table) const {
|
||||
block.setOnBlockDestroyed(table["on_block_destroyed"]);
|
||||
block.setTickRandomly(table["tick_randomly"].get_or(false));
|
||||
block.setTickProbability(table["tick_probability"].get_or(0.f));
|
||||
block.setCustomParamBits(table["custom_param_bits"].get_or<u8>(0));
|
||||
|
||||
BlockState &defaultState = block.getState(0);
|
||||
loadBlockState(defaultState, table, block);
|
||||
@ -242,5 +243,9 @@ inline void LuaBlockLoader::loadParams(ServerBlock &block) const {
|
||||
++bits;
|
||||
block.param().allocateBits(BlockParam::Type::State, bits);
|
||||
}
|
||||
|
||||
if (block.customParamBits()) {
|
||||
block.param().allocateBits(BlockParam::Type::Custom, block.customParamBits());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user