This commit is contained in:
@@ -139,7 +139,8 @@ namespace game::entity
|
||||
float Character::capacity_percent_get() const { return calories / max_capacity(); }
|
||||
|
||||
std::string Character::animation_name_convert(const std::string& name) { return std::format("{}{}", name, stage); }
|
||||
void Character::play_convert(const std::string& animation, Mode playMode, float startAtTime, float speedMultiplierValue)
|
||||
void Character::play_convert(const std::string& animation, Mode playMode, float startAtTime,
|
||||
float speedMultiplierValue)
|
||||
{
|
||||
play(animation_name_convert(animation), playMode, startAtTime, speedMultiplierValue);
|
||||
}
|
||||
@@ -225,7 +226,7 @@ namespace game::entity
|
||||
else
|
||||
isJustDigested = true;
|
||||
|
||||
weight = glm::clamp(data.weightMin, weight + increment, data.weightMax);
|
||||
weight += increment;
|
||||
|
||||
isDigesting = false;
|
||||
digestionTimer = data.digestionTimerMax;
|
||||
|
||||
@@ -4,11 +4,32 @@
|
||||
|
||||
using namespace game::util;
|
||||
|
||||
static ImFont* default_font_fallback_get()
|
||||
{
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
if (io.FontDefault) return io.FontDefault;
|
||||
if (!io.Fonts->Fonts.empty()) return io.Fonts->Fonts.front();
|
||||
return io.Fonts->AddFontDefault();
|
||||
}
|
||||
|
||||
namespace game::resource
|
||||
{
|
||||
Font::Font(const std::filesystem::path& path, float size)
|
||||
{
|
||||
auto pathString = path.string();
|
||||
std::error_code ec;
|
||||
|
||||
if (!std::filesystem::is_regular_file(path, ec))
|
||||
{
|
||||
logger.error(std::format("Failed to initialize font: {} (file not found)", pathString));
|
||||
internal = default_font_fallback_get();
|
||||
if (internal)
|
||||
logger.info(std::format("Falling back to default ImGui font: {}", pathString));
|
||||
else
|
||||
logger.error("Failed to initialize fallback ImGui default font");
|
||||
return;
|
||||
}
|
||||
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
@@ -18,7 +39,14 @@ namespace game::resource
|
||||
if (internal)
|
||||
logger.info(std::format("Initialized font: {}", pathString));
|
||||
else
|
||||
{
|
||||
logger.error(std::format("Failed to initialize font: {}", pathString));
|
||||
internal = default_font_fallback_get();
|
||||
if (internal)
|
||||
logger.info(std::format("Falling back to default ImGui font: {}", pathString));
|
||||
else
|
||||
logger.error("Failed to initialize fallback ImGui default font");
|
||||
}
|
||||
}
|
||||
|
||||
Font::Font(const physfs::Path& path, float size)
|
||||
@@ -27,6 +55,11 @@ namespace game::resource
|
||||
{
|
||||
logger.error(
|
||||
std::format("Failed to initialize font from PhysicsFS path: {} ({})", path.c_str(), physfs::error_get()));
|
||||
internal = default_font_fallback_get();
|
||||
if (internal)
|
||||
logger.info(std::format("Falling back to default ImGui font: {}", path.c_str()));
|
||||
else
|
||||
logger.error("Failed to initialize fallback ImGui default font");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,6 +69,22 @@ namespace game::resource
|
||||
{
|
||||
logger.error(
|
||||
std::format("Failed to initialize font from PhysicsFS path: {} ({})", path.c_str(), physfs::error_get()));
|
||||
internal = default_font_fallback_get();
|
||||
if (internal)
|
||||
logger.info(std::format("Falling back to default ImGui font: {}", path.c_str()));
|
||||
else
|
||||
logger.error("Failed to initialize fallback ImGui default font");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer.size() <= 100)
|
||||
{
|
||||
logger.error(std::format("Failed to initialize font from PhysicsFS path: {} (buffer too small)", path.c_str()));
|
||||
internal = default_font_fallback_get();
|
||||
if (internal)
|
||||
logger.info(std::format("Falling back to default ImGui font: {}", path.c_str()));
|
||||
else
|
||||
logger.error("Failed to initialize fallback ImGui default font");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,7 +96,14 @@ namespace game::resource
|
||||
if (internal)
|
||||
logger.info(std::format("Initialized font: {}", path.c_str()));
|
||||
else
|
||||
{
|
||||
logger.error(std::format("Failed to initialize font: {}", path.c_str()));
|
||||
internal = default_font_fallback_get();
|
||||
if (internal)
|
||||
logger.info(std::format("Falling back to default ImGui font: {}", path.c_str()));
|
||||
else
|
||||
logger.error("Failed to initialize fallback ImGui default font");
|
||||
}
|
||||
}
|
||||
|
||||
ImFont* Font::get() { return internal; };
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace game::resource::xml
|
||||
query_string_attribute(root, "Name", &name);
|
||||
|
||||
root->QueryFloatAttribute("Weight", &weight);
|
||||
root->QueryFloatAttribute("WeightMin", &weightMin);
|
||||
root->QueryFloatAttribute("WeightMax", &weightMax);
|
||||
|
||||
root->QueryFloatAttribute("Capacity", &capacity);
|
||||
root->QueryFloatAttribute("CapacityMin", &capacityMin);
|
||||
|
||||
@@ -117,8 +117,6 @@ namespace game::resource::xml
|
||||
std::string name{};
|
||||
std::filesystem::path path{};
|
||||
float weight{50};
|
||||
float weightMin{};
|
||||
float weightMax{999};
|
||||
float capacity{2000.0f};
|
||||
float capacityMin{2000.0f};
|
||||
float capacityMax{99999.0f};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "resources.hpp"
|
||||
|
||||
#include "util/preferences.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
using namespace game::resource;
|
||||
using namespace game::util;
|
||||
@@ -12,7 +13,19 @@ namespace game
|
||||
for (int i = 0; i < shader::COUNT; i++)
|
||||
shaders[i] = Shader(shader::INFO[i].vertex, shader::INFO[i].fragment);
|
||||
|
||||
for (auto& entry : std::filesystem::recursive_directory_iterator("resources/characters"))
|
||||
std::string CHARACTERS_DIRECTORY{"resources/characters"};
|
||||
std::error_code ec{};
|
||||
|
||||
if (!std::filesystem::is_directory(CHARACTERS_DIRECTORY, ec))
|
||||
{
|
||||
if (ec)
|
||||
logger.warning("Failed to read characters directory: " + CHARACTERS_DIRECTORY + " (" + ec.message() + ")");
|
||||
else
|
||||
logger.warning("Characters directory not found: " + CHARACTERS_DIRECTORY);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& entry : std::filesystem::recursive_directory_iterator(CHARACTERS_DIRECTORY))
|
||||
if (entry.is_regular_file() && entry.path().extension() == ".zip") characterPreviews.emplace_back(entry.path());
|
||||
characters.resize(characterPreviews.size());
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace game::state
|
||||
|
||||
character =
|
||||
entity::Character(data, vec2(World::BOUNDS.x + World::BOUNDS.z * 0.5f, World::BOUNDS.w - World::BOUNDS.y));
|
||||
character.digestionRate = glm::clamp(data.digestionRateMin, character.digestionRate, data.digestionRateMax);
|
||||
character.eatSpeed = glm::clamp(data.eatSpeedMin, character.eatSpeed, data.eatSpeedMax);
|
||||
character.capacity = glm::clamp(data.capacityMin, character.capacity, data.capacityMax);
|
||||
|
||||
auto isAlternateSpritesheet =
|
||||
(game == NEW_GAME && math::random_percent_roll(data.alternateSpritesheet.chanceOnNewGame));
|
||||
@@ -88,16 +91,13 @@ namespace game::state
|
||||
|
||||
isPostgame = saveData.isPostgame;
|
||||
|
||||
if (isPostgame)
|
||||
menu.isCheats = true;
|
||||
else
|
||||
menu.isCheats = false;
|
||||
if (isPostgame) menu.isCheats = true;
|
||||
|
||||
if (game == NEW_GAME) isWindows = false;
|
||||
|
||||
if (auto font = character.data.menuSchema.font.get()) ImGui::GetIO().FontDefault = font;
|
||||
|
||||
character.play_default_animation();
|
||||
character.queue_idle_animation();
|
||||
character.tick();
|
||||
worldCanvas.size_set(imgui::to_vec2(ImGui::GetMainViewport()->Size));
|
||||
world.set(character, worldCanvas, focus_get());
|
||||
@@ -170,7 +170,8 @@ namespace game::state
|
||||
}
|
||||
}
|
||||
|
||||
if (character.isJustStageFinal && !isEnd && !isPostgame) isEnd = true;
|
||||
if (character.isJustStageFinal && !isEnd && !isPostgame)
|
||||
isEnd = true;
|
||||
|
||||
if (isEnd)
|
||||
{
|
||||
@@ -199,6 +200,7 @@ namespace game::state
|
||||
isEndEnd = true;
|
||||
isEnd = false;
|
||||
isPostgame = true;
|
||||
world.character_focus(character, worldCanvas, focus_get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,13 +32,6 @@ namespace game::state::main
|
||||
ImGui::SameLine();
|
||||
if (WIDGET_FX(ImGui::Button("Digest"))) character.digestionProgress = entity::Character::DIGESTION_MAX;
|
||||
|
||||
if (WIDGET_FX(ImGui::SliderFloat("Weight", &character.weight, character.data.weightMin, character.data.weightMax,
|
||||
"%0.2f kg")))
|
||||
{
|
||||
character.stage = character.stage_get();
|
||||
character.queue_idle_animation();
|
||||
}
|
||||
|
||||
auto stage = character.stage + 1;
|
||||
if (WIDGET_FX(ImGui::SliderInt("Stage", &stage, 1, (int)character.data.stages.size() + 1)))
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace game::state::main
|
||||
class Cheats
|
||||
{
|
||||
public:
|
||||
|
||||
void update(Resources&, entity::Character&, Inventory&, Text&);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,6 +37,13 @@ namespace game::state::main
|
||||
|
||||
auto isImguiCaptureMouse = ImGui::GetIO().WantCaptureMouse;
|
||||
|
||||
auto isItemsLocked = character.isStageUp;
|
||||
|
||||
if (isItemsLocked)
|
||||
{
|
||||
heldItemIndex = -1;
|
||||
}
|
||||
|
||||
auto isMouseLeftClicked = ImGui::IsMouseClicked(ImGuiMouseButton_Left);
|
||||
auto isMouseLeftDown = ImGui::IsMouseDown(ImGuiMouseButton_Left);
|
||||
auto isMouseLeftReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Left);
|
||||
@@ -54,7 +61,7 @@ namespace game::state::main
|
||||
if (isJustItemHeldStopped || isJustItemThrown)
|
||||
{
|
||||
cursor.queue_default_animation();
|
||||
if (!isJustItemThrown) character.queue_idle_animation();
|
||||
if (!isJustItemThrown && !isItemsLocked) character.queue_idle_animation();
|
||||
isJustItemHeldStopped = false;
|
||||
isJustItemThrown = false;
|
||||
}
|
||||
@@ -115,10 +122,10 @@ namespace game::state::main
|
||||
|
||||
auto rect = character.null_frame_rect(eatArea.nullID);
|
||||
|
||||
if (isCanEat && math::is_point_in_rectf(rect, heldItem->position))
|
||||
if (isCanEat && math::is_point_in_rectf(rect, heldItem->position) && !isItemsLocked)
|
||||
{
|
||||
character.queue_play(
|
||||
{.animation = eatArea.animation, .speedMultiplier = character.eatSpeed, .isInterruptible = false});
|
||||
{.animation = eatArea.animation, .speedMultiplier = character.eatSpeed});
|
||||
|
||||
if (character.playedEventID == eatArea.eventID)
|
||||
{
|
||||
@@ -206,7 +213,7 @@ namespace game::state::main
|
||||
|
||||
item.update();
|
||||
|
||||
if (math::is_point_in_rectf(item.rect(), cursorPosition) && !isImguiCaptureMouse)
|
||||
if (math::is_point_in_rectf(item.rect(), cursorPosition) && !isImguiCaptureMouse && !isItemsLocked)
|
||||
{
|
||||
isItemHovered = true;
|
||||
cursor.queue_play({cursorSchema.animations.hover.get()});
|
||||
|
||||
@@ -91,13 +91,11 @@ namespace game::state::main
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
#if defined(DEBUG) && DEBUG
|
||||
if (WIDGET_FX(ImGui::BeginTabItem("Debug")))
|
||||
if (isDebug && WIDGET_FX(ImGui::BeginTabItem("Debug")))
|
||||
{
|
||||
debug.update(character, cursor, itemManager, canvas);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,14 @@ namespace game::state::main
|
||||
|
||||
state::Configuration configuration;
|
||||
|
||||
#if DEBUG
|
||||
bool isCheats{true};
|
||||
bool isDebug{true};
|
||||
#else
|
||||
bool isCheats{};
|
||||
bool isDebug{};
|
||||
#endif
|
||||
|
||||
bool isOpen{true};
|
||||
bool isChat{true};
|
||||
util::imgui::WindowSlide slide{};
|
||||
|
||||
Reference in New Issue
Block a user