metaforce/Runtime/CInGameTweakManagerBase.hpp

77 lines
2.2 KiB
C++
Raw Permalink Normal View History

2018-10-06 20:42:33 -07:00
#pragma once
2015-08-26 17:23:46 -07:00
#include <algorithm>
2015-08-26 17:23:46 -07:00
#include <string>
2016-07-23 21:46:32 -07:00
#include <vector>
2015-08-26 17:23:46 -07:00
#include "Runtime/RetroTypes.hpp"
2016-07-29 10:00:23 -07:00
2021-04-10 01:42:06 -07:00
namespace metaforce {
2015-08-26 17:23:46 -07:00
2018-12-07 21:30:43 -08:00
class CTweakValue {
2016-07-29 10:00:23 -07:00
public:
2018-12-07 21:30:43 -08:00
struct Audio {
float x0_fadeIn, x4_fadeOut, x8_volume;
std::string xc_fileName;
CAssetId x1c_res;
2019-04-06 22:14:48 -07:00
Audio() = default;
2018-12-07 21:30:43 -08:00
Audio(float fadeIn, float fadeOut, float vol, std::string_view fileName, u32 handle)
: x0_fadeIn(fadeIn), x4_fadeOut(fadeOut), x8_volume(vol), xc_fileName(fileName), x1c_res(handle) {}
float GetFadeIn() const { return x0_fadeIn; }
float GetFadeOut() const { return x4_fadeOut; }
float GetVolume() const { return x8_volume; }
std::string_view GetFileName() const { return xc_fileName; }
CAssetId GetResId() const { return x1c_res; }
static Audio None() { return Audio{0.f, 0.f, 0.f, "", 0}; }
};
enum class EType {};
2016-07-29 10:00:23 -07:00
private:
2018-12-07 21:30:43 -08:00
EType x0_type;
std::string x4_key;
std::string x14_str;
Audio x24_audio;
union {
u32 x44_int;
float x44_flt;
};
2016-07-29 10:00:23 -07:00
public:
2018-12-07 21:30:43 -08:00
CTweakValue() = default;
// CTweakValue(CTextInputStream&);
// void PutTo(CTextOutStream&);
std::string_view GetName() const { return x4_key; }
std::string_view GetValueAsString() const;
void SetValueFromString(std::string_view);
const Audio& GetAudio() const { return x24_audio; }
EType GetType() const { return x0_type; }
2016-07-23 21:46:32 -07:00
};
2018-12-07 21:30:43 -08:00
class CInGameTweakManagerBase {
2016-07-23 21:46:32 -07:00
protected:
2018-12-07 21:30:43 -08:00
std::vector<CTweakValue> x0_values;
2015-08-26 17:23:46 -07:00
public:
2018-12-07 21:30:43 -08:00
bool HasTweakValue(std::string_view name) const {
return std::any_of(x0_values.cbegin(), x0_values.cend(),
[name](const auto& value) { return value.GetName() == name; });
2018-12-07 21:30:43 -08:00
}
2016-07-23 21:46:32 -07:00
2018-12-07 21:30:43 -08:00
const CTweakValue* GetTweakValue(std::string_view name) const {
const auto iter = std::find_if(x0_values.cbegin(), x0_values.cend(),
[name](const auto& value) { return value.GetName() == name; });
if (iter == x0_values.cend()) {
return nullptr;
}
return &*iter;
2018-12-07 21:30:43 -08:00
}
2016-07-23 21:46:32 -07:00
2018-12-07 21:30:43 -08:00
bool ReadFromMemoryCard(std::string_view name) { return true; }
2017-05-21 09:01:04 -07:00
2018-12-07 21:30:43 -08:00
static std::string GetIdentifierForMidiEvent(CAssetId world, CAssetId area, std::string_view midiObj) {
2020-04-11 15:51:39 -07:00
return fmt::format(FMT_STRING("World {} Area {} MidiObject: {}"), world, area, midiObj);
2018-12-07 21:30:43 -08:00
}
2015-08-26 17:23:46 -07:00
};
2021-04-10 01:42:06 -07:00
} // namespace metaforce