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:
+3
-1
@@ -208,7 +208,9 @@ void Game::validate(Version v) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sort the update_cards_scripts from oldest to newest
|
// sort the update_cards_scripts from oldest to newest
|
||||||
std::sort(update_cards_scripts.begin(), update_cards_scripts.end());
|
std::sort(update_cards_scripts.begin(), update_cards_scripts.end(), [](const auto& a, const auto& b) {
|
||||||
|
return *a < *b;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::initCardListColorScript() {
|
void Game::initCardListColorScript() {
|
||||||
|
|||||||
+27
-15
@@ -207,27 +207,27 @@ void Set::validate(Version file_app_version) {
|
|||||||
script_manager->updateAll();
|
script_manager->updateAll();
|
||||||
// build uid map
|
// build uid map
|
||||||
buildUIDMap();
|
buildUIDMap();
|
||||||
// update cards with game update_cards_scripts
|
// update_cards_scripts
|
||||||
for (int j = 0; j < game->update_cards_scripts.size(); ++j) {
|
// first apply all the stylesheet scripts that are older than the first game script
|
||||||
UpdateCardsScriptP& script = game->update_cards_scripts[j];
|
// then apply the first game script
|
||||||
if (game_version >= script->before_version) continue;
|
// then apply all the stylesheet scripts that are older than the second game script
|
||||||
size_t size = cards.size();
|
// then apply the second game script, etc...
|
||||||
for (int i = 0; i < size; ++i) {
|
Version previous_cutoff = Version();
|
||||||
CardP& card = cards[i];
|
Version current_cutoff = Version();
|
||||||
vector<CardP> new_cards = script->perform(*this, card);
|
for (int g = 0; g < game->update_cards_scripts.size() + 1; ++g) {
|
||||||
if (!new_cards.empty()) {
|
bool last_iteration = g == game->update_cards_scripts.size();
|
||||||
--i;
|
UpdateCardsScriptP& game_script = last_iteration ? nullptr : game->update_cards_scripts[g];
|
||||||
--size;
|
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
|
||||||
}
|
|
||||||
// update cards with stylesheet update_cards_scripts
|
|
||||||
for (int i = 0; i < cards.size(); ++i) {
|
for (int i = 0; i < cards.size(); ++i) {
|
||||||
CardP& card = cards[i];
|
CardP& card = cards[i];
|
||||||
StyleSheetP stylesheet = card->stylesheet ? card->stylesheet : stylesheetForP(card);
|
StyleSheetP stylesheet = card->stylesheet ? card->stylesheet : stylesheetForP(card);
|
||||||
Version stylesheet_version = card->stylesheet_version.isZero() ? this->stylesheet_version : card->stylesheet_version;
|
Version stylesheet_version = card->stylesheet_version.isZero() ? this->stylesheet_version : card->stylesheet_version;
|
||||||
for (int j = 0; j < stylesheet->update_cards_scripts.size(); ++j) {
|
for (int j = 0; j < stylesheet->update_cards_scripts.size(); ++j) {
|
||||||
UpdateCardsScriptP& script = stylesheet->update_cards_scripts[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;
|
if (stylesheet_version >= script->before_version) continue;
|
||||||
vector<CardP> new_cards = script->perform(*this, card);
|
vector<CardP> new_cards = script->perform(*this, card);
|
||||||
if (!new_cards.empty()) {
|
if (!new_cards.empty()) {
|
||||||
@@ -242,6 +242,18 @@ void Set::validate(Version file_app_version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 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 = game_script->perform(*this, card);
|
||||||
|
if (!new_cards.empty()) {
|
||||||
|
--i;
|
||||||
|
--size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reflect_version_check(Reader& handler, const Char* key, intrusive_ptr<Packaged> const& package) {
|
void reflect_version_check(Reader& handler, const Char* key, intrusive_ptr<Packaged> const& package) {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ inline static void set_container(Value* container, ScriptValueP& value, String k
|
|||||||
else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(container)) {
|
else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(container)) {
|
||||||
String package_name = value->toString();
|
String package_name = value->toString();
|
||||||
while (package_name.starts_with(_("/"))) package_name = package_name.substr(1);
|
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)) {
|
else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(container)) {
|
||||||
cvalue->value = value->toColor();
|
cvalue->value = value->toColor();
|
||||||
|
|||||||
Reference in New Issue
Block a user