[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.
|
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`
|
||||||
|
|
||||||
Draw offset of the block.
|
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 {
|
void Block::serialize(sf::Packet &packet) const {
|
||||||
packet << u32(m_id) << m_stringID << m_canUpdate << m_canBeActivated
|
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) {
|
void Block::deserialize(sf::Packet &packet) {
|
||||||
u32 id;
|
u32 id;
|
||||||
packet >> id >> m_stringID >> m_canUpdate >> m_canBeActivated
|
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;
|
m_id = id;
|
||||||
|
|
||||||
for (auto &it : m_states) {
|
for (auto &it : m_states) {
|
||||||
|
@ -80,14 +80,17 @@ class Block : public gk::ISerializable {
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BlockParam ¶m() const { return m_param; }
|
|
||||||
BlockParam ¶m() { return m_param; }
|
|
||||||
|
|
||||||
BlockState &addState();
|
BlockState &addState();
|
||||||
BlockState &getState(u16 id);
|
BlockState &getState(u16 id);
|
||||||
const BlockState &getState(u16 id) const;
|
const BlockState &getState(u16 id) const;
|
||||||
const std::deque<BlockState> &states() const { return m_states; }
|
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);
|
static void initUsertype(sol::state &lua);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -107,6 +110,8 @@ class Block : public gk::ISerializable {
|
|||||||
std::deque<BlockState> m_states;
|
std::deque<BlockState> m_states;
|
||||||
|
|
||||||
BlockParam m_param{*this};
|
BlockParam m_param{*this};
|
||||||
|
|
||||||
|
u8 m_customParamBits = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLOCK_HPP_
|
#endif // BLOCK_HPP_
|
||||||
|
@ -49,6 +49,7 @@ class BlockParam : public gk::ISerializable {
|
|||||||
enum Type {
|
enum Type {
|
||||||
Rotation,
|
Rotation,
|
||||||
State,
|
State,
|
||||||
|
Custom,
|
||||||
|
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
@ -44,6 +44,7 @@ void LuaBlockLoader::loadBlock(const sol::table &table) const {
|
|||||||
block.setOnBlockDestroyed(table["on_block_destroyed"]);
|
block.setOnBlockDestroyed(table["on_block_destroyed"]);
|
||||||
block.setTickRandomly(table["tick_randomly"].get_or(false));
|
block.setTickRandomly(table["tick_randomly"].get_or(false));
|
||||||
block.setTickProbability(table["tick_probability"].get_or(0.f));
|
block.setTickProbability(table["tick_probability"].get_or(0.f));
|
||||||
|
block.setCustomParamBits(table["custom_param_bits"].get_or<u8>(0));
|
||||||
|
|
||||||
BlockState &defaultState = block.getState(0);
|
BlockState &defaultState = block.getState(0);
|
||||||
loadBlockState(defaultState, table, block);
|
loadBlockState(defaultState, table, block);
|
||||||
@ -242,5 +243,9 @@ inline void LuaBlockLoader::loadParams(ServerBlock &block) const {
|
|||||||
++bits;
|
++bits;
|
||||||
block.param().allocateBits(BlockParam::Type::State, 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