mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
apply update scripts in correct order
This commit is contained in:
+4
-2
@@ -207,8 +207,10 @@ void Game::validate(Version v) {
|
||||
card_links_alt_names.emplace(linked_tr, linked_default);
|
||||
}
|
||||
}
|
||||
// sort the update_cards_scripts from oldest to newest
|
||||
std::sort(update_cards_scripts.begin(), update_cards_scripts.end());
|
||||
// sort the update_cards_scripts from oldest to newest
|
||||
std::sort(update_cards_scripts.begin(), update_cards_scripts.end(), [](const auto& a, const auto& b) {
|
||||
return *a < *b;
|
||||
});
|
||||
}
|
||||
|
||||
void Game::initCardListColorScript() {
|
||||
|
||||
+38
-26
@@ -207,40 +207,52 @@ void Set::validate(Version file_app_version) {
|
||||
script_manager->updateAll();
|
||||
// build uid map
|
||||
buildUIDMap();
|
||||
// update cards with game update_cards_scripts
|
||||
for (int j = 0; j < game->update_cards_scripts.size(); ++j) {
|
||||
UpdateCardsScriptP& script = game->update_cards_scripts[j];
|
||||
if (game_version >= script->before_version) continue;
|
||||
// update_cards_scripts
|
||||
// first apply all the stylesheet scripts that are older than the first game script
|
||||
// then apply the first game script
|
||||
// then apply all the stylesheet scripts that are older than the second game script
|
||||
// then apply the second game script, etc...
|
||||
Version previous_cutoff = Version();
|
||||
Version current_cutoff = Version();
|
||||
for (int g = 0; g < game->update_cards_scripts.size() + 1; ++g) {
|
||||
bool last_iteration = g == game->update_cards_scripts.size();
|
||||
UpdateCardsScriptP& game_script = last_iteration ? nullptr : game->update_cards_scripts[g];
|
||||
previous_cutoff = current_cutoff;
|
||||
current_cutoff = last_iteration ? current_cutoff : game_script->before_version;
|
||||
// Apply stylesheet scripts that are older than the current game script
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
CardP& card = cards[i];
|
||||
StyleSheetP stylesheet = card->stylesheet ? card->stylesheet : stylesheetForP(card);
|
||||
Version stylesheet_version = card->stylesheet_version.isZero() ? this->stylesheet_version : card->stylesheet_version;
|
||||
for (int j = 0; j < stylesheet->update_cards_scripts.size(); ++j) {
|
||||
UpdateCardsScriptP& script = stylesheet->update_cards_scripts[j];
|
||||
if (script->before_version >= current_cutoff && !last_iteration) continue;
|
||||
if (script->before_version < previous_cutoff) continue;
|
||||
if (stylesheet_version >= script->before_version) continue;
|
||||
vector<CardP> new_cards = script->perform(*this, card);
|
||||
if (!new_cards.empty()) {
|
||||
FOR_EACH(new_card, new_cards) {
|
||||
// Initialize the stylesheet_version if it wasn't defined, to prevent this script from applying again
|
||||
if (stylesheet == stylesheetForP(new_card) && new_card->stylesheet_version < script->before_version) {
|
||||
new_card->stylesheet_version = script->before_version;
|
||||
}
|
||||
}
|
||||
--i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Apply current game script
|
||||
if (last_iteration || game_version >= current_cutoff) continue;
|
||||
size_t size = cards.size();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
CardP& card = cards[i];
|
||||
vector<CardP> new_cards = script->perform(*this, card);
|
||||
vector<CardP> new_cards = game_script->perform(*this, card);
|
||||
if (!new_cards.empty()) {
|
||||
--i;
|
||||
--size;
|
||||
}
|
||||
}
|
||||
}
|
||||
// update cards with stylesheet update_cards_scripts
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
CardP& card = cards[i];
|
||||
StyleSheetP stylesheet = card->stylesheet ? card->stylesheet : stylesheetForP(card);
|
||||
Version stylesheet_version = card->stylesheet_version.isZero() ? this->stylesheet_version : card->stylesheet_version;
|
||||
for (int j = 0; j < stylesheet->update_cards_scripts.size(); ++j) {
|
||||
UpdateCardsScriptP& script = stylesheet->update_cards_scripts[j];
|
||||
if (stylesheet_version >= script->before_version) continue;
|
||||
vector<CardP> new_cards = script->perform(*this, card);
|
||||
if (!new_cards.empty()) {
|
||||
FOR_EACH(new_card, new_cards) {
|
||||
// Initialize the stylesheet_version if it wasn't defined, to prevent this script from applying again
|
||||
if (stylesheet == stylesheetForP(new_card) && new_card->stylesheet_version < script->before_version) {
|
||||
new_card->stylesheet_version = script->before_version;
|
||||
}
|
||||
}
|
||||
--i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ inline static void set_container(Value* container, ScriptValueP& value, String k
|
||||
else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(container)) {
|
||||
String package_name = value->toString();
|
||||
while (package_name.starts_with(_("/"))) package_name = package_name.substr(1);
|
||||
pvalue->package_name = value->toString();
|
||||
pvalue->package_name = package_name;
|
||||
}
|
||||
else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(container)) {
|
||||
cvalue->value = value->toColor();
|
||||
|
||||
Reference in New Issue
Block a user