Small cleanup
This commit is contained in:
parent
ce6cadd2a0
commit
ca21b29f92
@ -42,7 +42,6 @@ MaterialItem::MaterialItem(Json const& config, String const& directory, Json con
|
|||||||
m_blockRadius = config.getFloat("blockRadius", defaultParameters.getFloat("blockRadius"));
|
m_blockRadius = config.getFloat("blockRadius", defaultParameters.getFloat("blockRadius"));
|
||||||
m_altBlockRadius = config.getFloat("altBlockRadius", defaultParameters.getFloat("altBlockRadius"));
|
m_altBlockRadius = config.getFloat("altBlockRadius", defaultParameters.getFloat("altBlockRadius"));
|
||||||
m_collisionOverride = TileCollisionOverrideNames.maybeLeft(config.getString("collisionOverride", "None")).value(TileCollisionOverride::None);
|
m_collisionOverride = TileCollisionOverrideNames.maybeLeft(config.getString("collisionOverride", "None")).value(TileCollisionOverride::None);
|
||||||
//TODO: Work out a vanilla-compatible way to network the 3 above for visual reasons without storing as a parameter, because that prevents stacking.
|
|
||||||
|
|
||||||
m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(materialDatabase->materialCollisionKind(m_material)));
|
m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(materialDatabase->materialCollisionKind(m_material)));
|
||||||
m_placeSounds = jsonToStringList(config.get("placeSounds", JsonArray()));
|
m_placeSounds = jsonToStringList(config.get("placeSounds", JsonArray()));
|
||||||
@ -68,7 +67,8 @@ void MaterialItem::init(ToolUserEntity* owner, ToolHand hand) {
|
|||||||
FireableItem::init(owner, hand);
|
FireableItem::init(owner, hand);
|
||||||
BeamItem::init(owner, hand);
|
BeamItem::init(owner, hand);
|
||||||
owner->addSound(Random::randValueFrom(m_placeSounds), 1.0f, 2.0f);
|
owner->addSound(Random::randValueFrom(m_placeSounds), 1.0f, 2.0f);
|
||||||
updateProperties();
|
if (auto player = as<Player>(owner))
|
||||||
|
updatePropertiesFromPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialItem::uninit() {
|
void MaterialItem::uninit() {
|
||||||
@ -85,39 +85,37 @@ void MaterialItem::update(float dt, FireMode fireMode, bool shifting, HashSet<Mo
|
|||||||
setEnd(BeamItem::EndType::TileGroup);
|
setEnd(BeamItem::EndType::TileGroup);
|
||||||
m_shifting = shifting;
|
m_shifting = shifting;
|
||||||
|
|
||||||
if (owner()->isMaster()) {
|
if (Player* player = as<Player>(owner())) {
|
||||||
Input& input = Input::singleton();
|
if (owner()->isMaster()) {
|
||||||
if (auto presses = input.bindDown("opensb", "materialCollisionCycle")) {
|
Input& input = Input::singleton();
|
||||||
CollisionKind baseKind = Root::singleton().materialDatabase()->materialCollisionKind(m_material);
|
if (auto presses = input.bindDown("opensb", "materialCollisionCycle")) {
|
||||||
for (size_t i = 0; i != *presses; ++i) {
|
CollisionKind baseKind = Root::singleton().materialDatabase()->materialCollisionKind(m_material);
|
||||||
constexpr auto limit = (uint8_t)TileCollisionOverride::Block + 1;
|
for (size_t i = 0; i != *presses; ++i) {
|
||||||
while (true) {
|
constexpr auto limit = (uint8_t)TileCollisionOverride::Block + 1;
|
||||||
m_collisionOverride = TileCollisionOverride(((uint8_t)m_collisionOverride + 1) % limit);
|
while (true) {
|
||||||
if (collisionKindFromOverride(m_collisionOverride) != baseKind)
|
m_collisionOverride = TileCollisionOverride(((uint8_t)m_collisionOverride + 1) % limit);
|
||||||
break;
|
if (collisionKindFromOverride(m_collisionOverride) != baseKind)
|
||||||
}
|
break;
|
||||||
if (auto player = as<Player>(owner()))
|
}
|
||||||
player->setSecretProperty(CollisionOverridePropertyKey, TileCollisionOverrideNames.getRight(m_collisionOverride));
|
player->setSecretProperty(CollisionOverridePropertyKey, TileCollisionOverrideNames.getRight(m_collisionOverride));
|
||||||
|
}
|
||||||
|
owner()->addSound("/sfx/tools/cyclematcollision.ogg", 1.0f, Random::randf(0.9f, 1.1f));
|
||||||
}
|
}
|
||||||
owner()->addSound("/sfx/tools/cyclematcollision.ogg", 1.0f, Random::randf(0.9f, 1.1f));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto presses = input.bindDown("opensb", "buildingRadiusGrow")) {
|
if (auto presses = input.bindDown("opensb", "buildingRadiusGrow")) {
|
||||||
m_blockRadius = min(BlockRadiusLimit, int(m_blockRadius + *presses));
|
m_blockRadius = min(BlockRadiusLimit, int(m_blockRadius + *presses));
|
||||||
if (auto player = as<Player>(owner()))
|
|
||||||
player->setSecretProperty(BlockRadiusPropertyKey, m_blockRadius);
|
player->setSecretProperty(BlockRadiusPropertyKey, m_blockRadius);
|
||||||
owner()->addSound("/sfx/tools/buildradiusgrow.wav", 1.0f, 1.0f + m_blockRadius / BlockRadiusLimit);
|
owner()->addSound("/sfx/tools/buildradiusgrow.wav", 1.0f, 1.0f + m_blockRadius / BlockRadiusLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto presses = input.bindDown("opensb", "buildingRadiusShrink")) {
|
if (auto presses = input.bindDown("opensb", "buildingRadiusShrink")) {
|
||||||
m_blockRadius = max(1, int(m_blockRadius - *presses));
|
m_blockRadius = max(1, int(m_blockRadius - *presses));
|
||||||
if (auto player = as<Player>(owner()))
|
|
||||||
player->setSecretProperty(BlockRadiusPropertyKey, m_blockRadius);
|
player->setSecretProperty(BlockRadiusPropertyKey, m_blockRadius);
|
||||||
owner()->addSound("/sfx/tools/buildradiusshrink.wav", 1.0f, 1.0f + m_blockRadius / BlockRadiusLimit);
|
owner()->addSound("/sfx/tools/buildradiusshrink.wav", 1.0f, 1.0f + m_blockRadius / BlockRadiusLimit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else {
|
updatePropertiesFromPlayer(player);
|
||||||
updateProperties();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,20 +267,18 @@ List<Drawable> const& MaterialItem::generatedPreview(Vec2I position) const {
|
|||||||
return *m_generatedPreviewCache;
|
return *m_generatedPreviewCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialItem::updateProperties() {
|
void MaterialItem::updatePropertiesFromPlayer(Player* player) {
|
||||||
if (auto player = as<Player>(owner())) {
|
auto blockRadius = player->getSecretProperty(BlockRadiusPropertyKey);
|
||||||
auto blockRadius = player->getSecretProperty(BlockRadiusPropertyKey);
|
if (blockRadius.isType(Json::Type::Float))
|
||||||
if (blockRadius.isType(Json::Type::Float))
|
m_blockRadius = blockRadius.toFloat();
|
||||||
m_blockRadius = blockRadius.toFloat();
|
|
||||||
|
|
||||||
auto altBlockRadius = player->getSecretProperty(AltBlockRadiusPropertyKey);
|
auto altBlockRadius = player->getSecretProperty(AltBlockRadiusPropertyKey);
|
||||||
if (altBlockRadius.isType(Json::Type::Float))
|
if (altBlockRadius.isType(Json::Type::Float))
|
||||||
m_altBlockRadius = altBlockRadius.toFloat();
|
m_altBlockRadius = altBlockRadius.toFloat();
|
||||||
|
|
||||||
auto collisionOverride = player->getSecretProperty(CollisionOverridePropertyKey);
|
auto collisionOverride = player->getSecretProperty(CollisionOverridePropertyKey);
|
||||||
if (collisionOverride.isType(Json::Type::String))
|
if (collisionOverride.isType(Json::Type::String))
|
||||||
m_collisionOverride = TileCollisionOverrideNames.maybeLeft(collisionOverride.toString()).value(TileCollisionOverride::None);
|
m_collisionOverride = TileCollisionOverrideNames.maybeLeft(collisionOverride.toString()).value(TileCollisionOverride::None);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float MaterialItem::calcRadius(bool shifting) const {
|
float MaterialItem::calcRadius(bool shifting) const {
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
List<PreviewTile> previewTiles(bool shifting) const override;
|
List<PreviewTile> previewTiles(bool shifting) const override;
|
||||||
List<Drawable> const& generatedPreview(Vec2I position = {}) const;
|
List<Drawable> const& generatedPreview(Vec2I position = {}) const;
|
||||||
private:
|
private:
|
||||||
void updateProperties();
|
void updatePropertiesFromPlayer(Player* player);
|
||||||
float calcRadius(bool shifting) const;
|
float calcRadius(bool shifting) const;
|
||||||
List<Vec2I>& tileArea(float radius, Vec2F const& position) const;
|
List<Vec2I>& tileArea(float radius, Vec2F const& position) const;
|
||||||
MaterialHue placementHueShift(Vec2I const& position) const;
|
MaterialHue placementHueShift(Vec2I const& position) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user