Add binds to modify material radius

This commit is contained in:
Kae 2023-08-20 13:57:27 +10:00
parent 70ab7cade0
commit e5c6d005d7
6 changed files with 68 additions and 15 deletions

View File

@ -28,10 +28,20 @@
"group": "voice", "group": "voice",
"name": "Push To Talk" "name": "Push To Talk"
}, },
"materialCycleCollision": { "materialCollisionCycle": {
"default": [], "default": [],
"group": "building", "group": "building",
"name": "Cycle Material Collision" "name": "Cycle Material Collision"
},
"materialRadiusGrow": {
"default": [],
"group": "building",
"name": "Grow Material Radius"
},
"materialRadiusShrink": {
"default": [],
"group": "building",
"name": "Shrink Material Radius"
} }
} }
} }

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,13 @@
namespace Star { namespace Star {
EnumMap<TileCollisionOverride> const TileCollisionOverrideNames = {
{TileCollisionOverride::None, "None"},
{TileCollisionOverride::Empty, "Empty"},
{TileCollisionOverride::Platform, "Platform"},
{TileCollisionOverride::Block, "Block"}
};
EnumMap<CollisionKind> const CollisionKindNames{ EnumMap<CollisionKind> const CollisionKindNames{
{CollisionKind::Null, "Null"}, {CollisionKind::Null, "Null"},
{CollisionKind::None, "None"}, {CollisionKind::None, "None"},

View File

@ -59,6 +59,8 @@ CollisionSet const DefaultCollisionSet({CollisionKind::Null, CollisionKind::Slip
// Defines what can be "blocks" e.g. for tile rendering: Block and Slippery // Defines what can be "blocks" e.g. for tile rendering: Block and Slippery
CollisionSet const BlockCollisionSet({CollisionKind::Block, CollisionKind::Slippery}); CollisionSet const BlockCollisionSet({CollisionKind::Block, CollisionKind::Slippery});
extern EnumMap<TileCollisionOverride> const TileCollisionOverrideNames;
extern EnumMap<CollisionKind> const CollisionKindNames; extern EnumMap<CollisionKind> const CollisionKindNames;
bool isColliding(CollisionKind kind, CollisionSet const& collisionSet); bool isColliding(CollisionKind kind, CollisionSet const& collisionSet);

View File

@ -11,6 +11,8 @@
namespace Star { namespace Star {
constexpr int BlockRadiusLimit = 16;
MaterialItem::MaterialItem(Json const& config, String const& directory, Json const& settings) MaterialItem::MaterialItem(Json const& config, String const& directory, Json const& settings)
: Item(config, directory, settings), FireableItem(config), BeamItem(config) { : Item(config, directory, settings), FireableItem(config), BeamItem(config) {
m_material = config.getInt("materialId"); m_material = config.getInt("materialId");
@ -31,11 +33,13 @@ MaterialItem::MaterialItem(Json const& config, String const& directory, Json con
auto defaultParameters = Root::singleton().assets()->json("/items/defaultParameters.config"); auto defaultParameters = Root::singleton().assets()->json("/items/defaultParameters.config");
setCooldownTime(config.queryFloat("materialItems.cooldown", defaultParameters.queryFloat("materialItems.cooldown"))); setCooldownTime(config.queryFloat("materialItems.cooldown", defaultParameters.queryFloat("materialItems.cooldown")));
m_blockRadius = config.getFloat("blockRadius", defaultParameters.getFloat("blockRadius")); m_blockRadius = instanceValue("blockRadius", defaultParameters.getFloat("blockRadius")).toFloat();
m_altBlockRadius = config.getFloat("altBlockRadius", defaultParameters.getFloat("altBlockRadius")); m_altBlockRadius = instanceValue("altBlockRadius", defaultParameters.getFloat("altBlockRadius")).toFloat();
auto materialDatabase = Root::singleton().materialDatabase(); auto materialDatabase = Root::singleton().materialDatabase();
m_multiplace = config.getBool("allowMultiplace", BlockCollisionSet.contains(materialDatabase->materialCollisionKind(m_material))); auto multiplace = instanceValue("allowMultiplace", BlockCollisionSet.contains(materialDatabase->materialCollisionKind(m_material)));
if (multiplace.isType(Json::Type::Bool))
m_multiplace = multiplace.toBool();
m_placeSounds = jsonToStringList(config.get("placeSounds", JsonArray())); m_placeSounds = jsonToStringList(config.get("placeSounds", JsonArray()));
if (m_placeSounds.empty()) { if (m_placeSounds.empty()) {
auto miningSound = materialDatabase->miningSound(m_material); auto miningSound = materialDatabase->miningSound(m_material);
@ -49,7 +53,7 @@ MaterialItem::MaterialItem(Json const& config, String const& directory, Json con
} }
m_shifting = false; m_shifting = false;
m_lastTileAreaRadiusCache = 0.0f; m_lastTileAreaRadiusCache = 0.0f;
m_collisionOverride = TileCollisionOverride::None; m_collisionOverride = TileCollisionOverrideNames.maybeLeft(instanceValue("collisionOverride", "None").toString()).value(TileCollisionOverride::None);
} }
ItemPtr MaterialItem::clone() const { ItemPtr MaterialItem::clone() const {
@ -69,23 +73,53 @@ void MaterialItem::uninit() {
void MaterialItem::update(float dt, FireMode fireMode, bool shifting, HashSet<MoveControlType> const& moves) { void MaterialItem::update(float dt, FireMode fireMode, bool shifting, HashSet<MoveControlType> const& moves) {
FireableItem::update(dt, fireMode, shifting, moves); FireableItem::update(dt, fireMode, shifting, moves);
BeamItem::update(dt, fireMode, shifting, moves); BeamItem::update(dt, fireMode, shifting, moves);
if (shifting || !multiplaceEnabled()) float radius = calcRadius(shifting);
if (radius == 1)
setEnd(BeamItem::EndType::Tile); setEnd(BeamItem::EndType::Tile);
else else
setEnd(BeamItem::EndType::TileGroup); setEnd(BeamItem::EndType::TileGroup);
m_shifting = shifting; m_shifting = shifting;
if (auto presses = Input::singleton().bindDown("opensb", "materialCycleCollision")) { if (owner()->isMaster()) {
CollisionKind baseKind = Root::singleton().materialDatabase()->materialCollisionKind(m_material); Input& input = Input::singleton();
for (size_t i = 0; i != *presses; ++i) { if (auto presses = input.bindDown("opensb", "materialCollisionCycle")) {
constexpr auto limit = (uint8_t)TileCollisionOverride::Block + 1; CollisionKind baseKind = Root::singleton().materialDatabase()->materialCollisionKind(m_material);
while (true) { for (size_t i = 0; i != *presses; ++i) {
m_collisionOverride = (TileCollisionOverride)(((uint8_t)m_collisionOverride + 1) % limit); constexpr auto limit = (uint8_t)TileCollisionOverride::Block + 1;
if (collisionKindFromOverride(m_collisionOverride) != baseKind) while (true) {
break; m_collisionOverride = TileCollisionOverride(((uint8_t)m_collisionOverride + 1) % limit);
setInstanceValue("collisionOverride", TileCollisionOverrideNames.getRight(m_collisionOverride));
if (collisionKindFromOverride(m_collisionOverride) != baseKind)
break;
}
} }
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", "materialRadiusGrow")) {
m_blockRadius = min(BlockRadiusLimit, int(m_blockRadius + *presses));
setInstanceValue("blockRadius", m_blockRadius);
owner()->addSound("/sfx/tools/matradiusgrow.wav", 1.0f, 1.0f + m_blockRadius / BlockRadiusLimit);
}
if (auto presses = input.bindDown("opensb", "materialRadiusShrink")) {
m_blockRadius = max(1, int(m_blockRadius - *presses));
setInstanceValue("blockRadius", m_blockRadius);
owner()->addSound("/sfx/tools/matradiusshrink.wav", 1.0f, 1.0f + m_blockRadius / BlockRadiusLimit);
}
}
else {
auto blockRadius = instanceValue("blockRadius");
if (blockRadius.isType(Json::Type::Float))
m_blockRadius = blockRadius.toFloat();
auto altBlockRadius = instanceValue("altBlockRadius");
if (altBlockRadius.isType(Json::Type::Float))
m_altBlockRadius = altBlockRadius.toFloat();
auto collisionOverride = instanceValue("collisionOverride");
if (collisionOverride.isType(Json::Type::String))
m_collisionOverride = TileCollisionOverrideNames.maybeLeft(collisionOverride.toString()).value(TileCollisionOverride::None);
} }
} }