2019-06-14 12:59:38 +00:00
|
|
|
|
|
|
|
#include "UserData.hpp"
|
2019-06-14 20:21:33 +00:00
|
|
|
#include "UserDataStorage.hpp"
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon::UserData {
|
|
|
|
extern "C" {
|
2019-09-07 13:22:24 +00:00
|
|
|
void RegisterUserDataType(char16_t * key) {
|
|
|
|
auto hashedKey = new Utilities::HashedString(new u16string(key));
|
|
|
|
auto ud = new UserData(hashedKey, {});
|
|
|
|
UserDataStorage::RegisterType(hashedKey->GetHash(), ud);
|
2019-06-14 20:21:33 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
void RegisterUserDataField(uint32_t typeId, uint32_t fieldId, UserDataField *field) {
|
2019-06-14 20:21:33 +00:00
|
|
|
auto ud = UserDataStorage::GetUserDataType(typeId);
|
2019-08-25 09:53:37 +00:00
|
|
|
ud->Get()->CreateField(fieldId, field);
|
2019-06-14 20:21:33 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
int32_t GetUserDataFieldCount(uint32_t typeId) {
|
2019-06-14 20:21:33 +00:00
|
|
|
auto ud = UserDataStorage::GetUserDataType(typeId);
|
2019-08-25 09:53:37 +00:00
|
|
|
return ud->Get()->GetFieldCount();
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
2019-09-01 11:35:13 +00:00
|
|
|
|
|
|
|
void SetIsCastableFunc(uint32_t typeId, bool (*cast)(const ScriptType*, bool)){
|
|
|
|
auto ud = UserDataStorage::GetUserDataType(typeId);
|
|
|
|
ud->Get()->SetIsCastable(cast);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCastFunc(uint32_t typeId, Evaluation::EvalValue* (*cast)(void*, const ScriptType*)){
|
|
|
|
auto ud = UserDataStorage::GetUserDataType(typeId);
|
|
|
|
ud->Get()->SetCastFunc(cast);
|
|
|
|
}
|
2019-06-14 20:21:33 +00:00
|
|
|
}
|
|
|
|
}
|