1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Use ptr to identify rmg template

This commit is contained in:
nordsoft 2022-09-19 03:17:39 +04:00
parent c348c1a053
commit 097fe2584b
4 changed files with 24 additions and 12 deletions

@ -13,6 +13,24 @@
#include <QString>
#include <QFile>
using NumericPointer = unsigned long long;
template<class Type>
NumericPointer data_cast(Type * _pointer)
{
static_assert(sizeof(Type *) == sizeof(NumericPointer),
"Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
return reinterpret_cast<NumericPointer>(_pointer);
}
template<class Type>
Type * data_cast(NumericPointer _numeric)
{
static_assert(sizeof(Type *) == sizeof(NumericPointer),
"Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
return reinterpret_cast<Type *>(_numeric);
}
inline QString pathToQString(const boost::filesystem::path & path)
{
#ifdef VCMI_WINDOWS

@ -573,10 +573,7 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant
//===============IMPLEMENT PROPERTY VALUE TYPE============================
QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
{
using NumericPointer = unsigned long long;
static_assert(sizeof(CGObjectInstance *) == sizeof(NumericPointer),
"Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
return new QTableWidgetItem(QString::number(reinterpret_cast<NumericPointer>(value)));
return new QTableWidgetItem(QString::number(data_cast<CGObjectInstance>(value)));
}
QTableWidgetItem * Inspector::addProperty(Inspector::PropertyEditorPlaceholder value)

@ -924,10 +924,7 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item)
//get identifier
auto identifier = tableWidget->item(0, 1)->text();
static_assert(sizeof(CGObjectInstance *) == sizeof(decltype(identifier.toLongLong())),
"Compilied for 64 bit arcitecture. Use .toInt() method");
CGObjectInstance * obj = reinterpret_cast<CGObjectInstance *>(identifier.toLongLong());
CGObjectInstance * obj = data_cast<CGObjectInstance>(identifier.toLongLong());
//get parameter name
auto param = tableWidget->item(r, c - 1)->text();

@ -350,8 +350,8 @@ void WindowNewMap::on_templateCombo_activated(int index)
mapGenOptions.setMapTemplate(nullptr);
return;
}
auto * templ = VLC->tplh->getTemplate(ui->templateCombo->currentText().toStdString());
auto * templ = data_cast<const CRmgTemplate>(ui->templateCombo->currentData().toLongLong());
mapGenOptions.setMapTemplate(templ);
}
@ -390,11 +390,11 @@ void WindowNewMap::updateTemplateList()
if(templates.empty())
return;
ui->templateCombo->addItem("[default]");
ui->templateCombo->addItem("[default]", 0);
for(auto * templ : templates)
{
ui->templateCombo->addItem(QString::fromStdString(templ->getName()));
ui->templateCombo->addItem(QString::fromStdString(templ->getName()), data_cast(templ));
}
ui->templateCombo->setCurrentIndex(0);