Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MissionEditor/CellTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ BOOL CCellTag::OnInitDialog()

CComboBox& m_Tag = *((CComboBox*)GetDlgItem(IDC_TAG));

if (!TagDatabase::Instance().Size()) {
if (!DB::Tags.Size()) {
MessageBox("No tags are specified.");
OnCancel();
} else {
Expand Down
12 changes: 6 additions & 6 deletions MissionEditor/FinalSunDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,8 @@ void CFinalSunDlg::SaveMap(CString FileName_)

CIniFile& ini = Map->GetIniFile();

TriggerDatabase::Instance().SaveInto(ini, errstream);
TagDatabase::Instance().SaveInto(ini, errstream);
DB::Triggers.SaveInto(ini, errstream);
DB::Tags.SaveInto(ini, errstream);

// delete invalid ini sections
for (auto it = ini.begin(); it != ini.end();) {
Expand Down Expand Up @@ -1785,8 +1785,8 @@ void CFinalSunDlg::OnFileNew()
ini.DeleteSection("CellTags");
// ini.sections.erase("AITriggerTypesEnable");
// ini.sections.erase("AITriggerTypes");
TriggerDatabase::Instance().Clear();
TagDatabase::Instance().Clear();
DB::Triggers.Clear();
DB::Tags.Clear();
}
}

Expand Down Expand Up @@ -1848,8 +1848,8 @@ void CFinalSunDlg::OnFileNew()
ini.SetString("Basic", "Player", plhouse);

auto const& rulesHouseSec = rules[HOUSES];
auto& triggerDb = TriggerDatabase::Instance();
auto& tagDb = TagDatabase::Instance();
auto& triggerDb = DB::Triggers;
auto& tagDb = DB::Tags;

for (auto idx = 0; idx < rulesHouseSec.Size(); idx++) {
#ifdef RA2_MODE
Expand Down
30 changes: 19 additions & 11 deletions MissionEditor/IsoView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2864,16 +2864,21 @@ void CIsoView::OnLButtonDown(UINT nFlags, CPoint point)
if (AD.type == 2) {
// change celltag properties
int n = Map->GetCelltagAt(x + y * Map->GetIsoSize());
if (n < 0) return;

if (n < 0) {
return;
}
DWORD dwPos;
CString tag;

Map->GetCelltagData(n, &tag, &dwPos);

CCellTag dlg(this);
auto const& tagData = TagDatabase::Instance().Lookup(tag);
dlg.m_tag.Format("%s (%s)", tagData.id, tagData.name);

if (auto const tagData = DB::Tags.TryLookup(tag)) {
dlg.m_tag.Format("%s (%s)", tagData->id, tagData->name);
} else {
dlg.m_tag = tag;
}

if (dlg.DoModal() == IDCANCEL) {
return;
Expand Down Expand Up @@ -4123,9 +4128,11 @@ void CIsoView::UpdateStatusBar(int x, int y)
if (techno.tag != "None" && !techno.tag.IsEmpty()) {
statusbar += ", Tag: ";
statusbar += techno.tag;
statusbar += ' ';
auto const& tagData = TagDatabase::Instance().Lookup(techno.tag);
statusbar += tagData.name;

if (auto const tagData = DB::Tags.TryLookup(techno.tag)) {
statusbar += ' ';
statusbar += tagData->name;
}
}
}

Expand Down Expand Up @@ -4160,13 +4167,14 @@ void CIsoView::UpdateStatusBar(int x, int y)
DWORD pos;
Map->GetCelltagData(n, &tagId, &pos);

statusbar += GetLanguageStringACP("CellTagStatus");

if (tagId != "None" && !tagId.IsEmpty()) {
auto const& tagData = TagDatabase::Instance().Lookup(tagId);
name = tagData.name;
if (auto const tagData = DB::Tags.TryLookup(tagId)) {
statusbar += tagData->name;
}
}

statusbar += GetLanguageStringACP("CellTagStatus");
statusbar += name;
statusbar += " (";
statusbar += tagId;
statusbar += ")";
Expand Down
6 changes: 3 additions & 3 deletions MissionEditor/MapData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ void CMapData::LoadMap(const CString& file)


UpdateIniFile(MAPDATA_UPDATE_FROM_INI);
TriggerDatabase::Instance().LoadFrom(m_mapfile, errstream);
TagDatabase::Instance().LoadFrom(m_mapfile, errstream);
DB::Triggers.LoadFrom(m_mapfile, errstream);
DB::Tags.LoadFrom(m_mapfile, errstream);
}


Expand Down Expand Up @@ -6446,7 +6446,7 @@ BOOL CMapData::IsYRMap()
}
}

auto const& triggerDb = TriggerDatabase::Instance();
auto const& triggerDb = DB::Triggers;
auto const& eventDefs = TriggerDefinitionManager::Instance().Events();
for (auto const& trigger : triggerDb) {
auto const& actionParams = trigger.Actions();
Expand Down
4 changes: 2 additions & 2 deletions MissionEditor/MapValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ BOOL CMapValidator::CheckMap()

}

auto const& triggerDb = TriggerDatabase::Instance();
auto const& tagDb = TagDatabase::Instance();
auto const& triggerDb = DB::Triggers;
auto const& tagDb = DB::Tags;
for (auto const& tag : tagDb) {
auto const& trigger = tag.triggerId;
if (!triggerDb.Exists(trigger)) {
Expand Down
28 changes: 14 additions & 14 deletions MissionEditor/Tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ void CTags::UpdateDialog()
while (m_Trigger.DeleteString(0) != CB_ERR);

int i;
auto const& tagDb = TagDatabase::Instance();
auto const& tagDb = DB::Tags;
for (auto const& tag : tagDb) {
CString s;
s.Format("%s (%s)", tag.id, tag.name);
m_Tag.AddString(s);
}

auto const& triggerDb = TriggerDatabase::Instance();
auto const& triggerDb = DB::Triggers;
for (auto const& trigger: triggerDb) {
CString s;
s.Format("%s (%s)", trigger.ID(), trigger.Options().name);
s.Format("%s (%s)", trigger.ID(), trigger.Options().Name());
m_Trigger.AddString(s);
}

Expand Down Expand Up @@ -177,15 +177,15 @@ void CTags::OnSelchangeTag()
m_Tag.GetLBText(index, type);
TruncSpace(type);

auto const& tagDb = TagDatabase::Instance();
auto const& tagDb = DB::Tags;
auto const& data = tagDb.Lookup(type);
m_Name = data.name;
auto const& triggerId = data.triggerId;
CString desc = triggerId;

auto const& triggerDb = TriggerDatabase::Instance();
auto const& triggerDb = DB::Triggers;

desc.Format("%s (%s)", triggerId, triggerDb.Lookup(triggerId).Options().name);
desc.Format("%s (%s)", triggerId, triggerDb.Lookup(triggerId).Options().Name());

m_Trigger.SetWindowText(desc);
m_Repeat.SetWindowText(data.PersistenceString());
Expand All @@ -210,7 +210,7 @@ void CTags::OnChangeName()
m_Tag.GetLBText(index, type);
TruncSpace(type);

auto& data = TagDatabase::Instance().Lookup(type);
auto& data = DB::Tags.Lookup(type);
data.name = m_Name;

UpdateDialog();
Expand All @@ -234,7 +234,7 @@ void CTags::OnEditchangeRepeat()
m_Tag.GetLBText(index, type);
TruncSpace(type);

auto& data = TagDatabase::Instance().Lookup(type);
auto& data = DB::Tags.Lookup(type);
data.persistence = atoi(str); // TODO: validate str

UpdateDialog();
Expand All @@ -260,7 +260,7 @@ void CTags::OnSelchangeRepeat()

TruncSpace(str);

auto& data = TagDatabase::Instance().Lookup(type);
auto& data = DB::Tags.Lookup(type);
data.persistence = atoi(str); // TODO: validate str

UpdateDialog();
Expand All @@ -281,7 +281,7 @@ void CTags::OnEditchangeTrigger()
m_Tag.GetLBText(index, type);
TruncSpace(type);

auto& data = TagDatabase::Instance().Lookup(type);
auto& data = DB::Tags.Lookup(type);
data.triggerId = str; // TODO: validate str

//UpdateDialog();
Expand All @@ -307,7 +307,7 @@ void CTags::OnSelchangeTrigger()
m_Tag.GetLBText(index, type);
TruncSpace(type);

auto& data = TagDatabase::Instance().Lookup(type);
auto& data = DB::Tags.Lookup(type);
data.triggerId = str; // TODO: validate str

//UpdateDialog();
Expand All @@ -327,20 +327,20 @@ void CTags::OnDelete()
return;
}

TagDatabase::Instance().DeleteAt(index);
DB::Tags.DeleteAt(index);

UpdateDialog();
}

void CTags::OnAdd()
{
auto const& triggerDb = TriggerDatabase::Instance();
auto const& triggerDb = DB::Triggers;
if (triggerDb.Size() <= 0) {
MessageBox(TranslateStringACP("TagCreateWarning"), TranslateStringACP("Error"));
return;
};

auto& tag = TagDatabase::Instance().
auto& tag = DB::Tags.
Append(GetFreeID(), "New Tag");
tag.triggerId = triggerDb.Nth(0).ID();

Expand Down
8 changes: 5 additions & 3 deletions MissionEditor/TeamTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,13 @@ void CTeamTypes::OnSelchangeTeamtypes()
m_Suicide = sec.GetBool("Suicide");

auto const& tagId = sec.GetString("Tag");
auto& tagDb = TagDatabase::Instance();
auto& tagDb = DB::Tags;
if (!tagId.IsEmpty()) {
m_Tag = tagId;
auto const& tagData = tagDb.Lookup( tagId);
m_Tag.Format("%s %s", tagId, tagData.name);
if (auto const tagData = tagDb.TryLookup(tagId)) {
m_Tag += ' ';
m_Tag += tagData->name;
}
} else {
m_Tag = GetLanguageStringACP("None");
}
Expand Down
53 changes: 40 additions & 13 deletions MissionEditor/TriggerDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ const TriggerInstance TriggerInstance::Default {
"0"
};

template<>
ObjectDatabase<TriggerInstance>& ObjectDatabase<TriggerInstance>::Instance()
{
static ObjectDatabase inst;
return inst;
}
template<>
ObjectDatabase<TagInstance>& ObjectDatabase<TagInstance>::Instance()
{
static ObjectDatabase inst;
return inst;
}

template<>
void ObjectDatabase<TriggerInstance>::LoadFrom(const CIniFile& ini, std::ostream& err)
{
Expand All @@ -34,6 +21,13 @@ void ObjectDatabase<TriggerInstance>::LoadFrom(const CIniFile& ini, std::ostream
items.emplace_back(id, ini);
lookupTable.try_emplace(id, items.size() - 1);
}

if (indexUpdateHandler) {
for (auto const& item : items) {
auto const& id = item.ID();
indexUpdateHandler(GetIndexByKey(id), id, DBOp::Add);
}
}
}

template<>
Expand Down Expand Up @@ -77,6 +71,15 @@ TriggerInstance::TriggerInstance(CString&& id, CString&& name, CString&& house)
this->Options().house = std::move(house);
}

void TriggerInstance::SetName(const CString& name, bool updateIndex)
{
auto const oldName = std::exchange(Options().name, name);
if (updateIndex && oldName != name) {
DB::Triggers.OnUpdateIndex(oldName, id, DBOp::Delete);
DB::Triggers.OnUpdateIndex(name, id, DBOp::Add);
}
}

// ---------------------------- TagDatabase --------------------------
template<>
void ObjectDatabase<TagInstance>::LoadFrom(const CIniFile& ini, std::ostream& err)
Expand All @@ -101,3 +104,27 @@ void ObjectDatabase<TagInstance>::SaveInto(CIniFile& ini, std::ostream& err)
tagSec.SetString(tag.id, tag.Serialize());
}
}

// This is a name - id reverse mapping
// e.g.
// - Print String (0000000004)
// - Print String (0000000005)
// - Team A Ready To Move (0000000006)
// - Team B Ready To Move (0000000002)
// so the Idx here is Trigger's name, while ID is the primK
void TriggerDatabase::OnUpdateIndex(const CString& idx, const CString& primK, const DBOp op)
{
if (op == DBOp::Add) {
customIndexTable.emplace(idx, primK);
return;
}
// delete
auto [it, last] = customIndexTable.equal_range(idx);
for (; it != last;) {
if (it->second == primK) {
it = customIndexTable.erase(it);
break; // no duplicated elements allowed right ?
}
++it;
}
}
Loading
Loading