def test_find_database_errors(game_enum: RandovaniaGame):
    # Setup
    game = default_database.game_description_for(game_enum)

    # Run
    errors = integrity_check.find_database_errors(game)

    # Assert
    assert errors == []
Exemple #2
0
    def _save_database(self, path: Path) -> bool:
        errors = integrity_check.find_database_errors(self.game_description)
        if errors:
            if not self.display_integrity_errors_warning(errors):
                return False

        data = data_writer.write_game_description(self.game_description)
        if self._is_internal:
            path.with_suffix("").mkdir(exist_ok=True)
            data_writer.write_as_split_files(data, path.with_suffix(""))
        else:
            with path.open("w") as open_file:
                json.dump(data, open_file, indent=4)
        self._last_data = data
        return True
Exemple #3
0
def refresh_all_logic(args):
    from randovania.game_description import pretty_print
    from randovania.game_description import data_reader, data_writer
    from randovania.game_description import integrity_check

    gd_per_game = {}
    path_per_game = {}
    idb_per_game = {}

    for game in iterate_enum(RandovaniaGame):
        logging.info("Reading %s", game.long_name)
        path, data = default_data.read_json_then_binary(game)
        path_per_game[game] = path
        gd = data_reader.decode_data(data)
        gd_per_game[game] = gd

        idb = default_database.item_database_for_game(game)
        idb_per_game[game] = idb

    should_stop = False
    if args.integrity_check:
        for game, gd in gd_per_game.items():
            errors = integrity_check.find_database_errors(gd)
            if errors:
                logging.warning("Integrity errors for %s:\n%s", game.long_name,
                                "\n".join(errors))
                if game.data.development_state.is_stable:
                    should_stop = True

    if should_stop:
        return

    for game, gd in gd_per_game.items():
        path = path_per_game[game]
        logging.info("Writing %s", game.long_name)
        new_data = data_writer.write_game_description(gd)
        data_writer.write_as_split_files(new_data, path)
        path.with_suffix("").mkdir(parents=True, exist_ok=True)
        pretty_print.write_human_readable_game(gd, path.with_suffix(""))

        default_database.write_item_database_for_game(idb_per_game[game], game)
def test_invalid_db():
    sample_data = {
        "schema_version":
        6,
        "game":
        "prime2",
        "resource_database": {
            "items": {},
            "events": {},
            "tricks": {},
            "damage": {},
            "versions": {},
            "misc": {},
            "requirement_template": {},
            "damage_reductions": [],
            "energy_tank_item_index": "Power",
            "item_percentage_index": "Power",
            "multiworld_magic_item_index": "Power"
        },
        "starting_location": {
            "world_name": "World",
            "area_name": "Area 2"
        },
        "initial_states": {
            "Default": []
        },
        "minimal_logic":
        None,
        "victory_condition": {
            "type": "and",
            "data": {
                "comment": None,
                "items": []
            }
        },
        "dock_weakness_database": {
            "types": {
                "door": {
                    "name": "Door",
                    "extra": {},
                    "items": {}
                },
                "portal": {
                    "name": "Portal",
                    "extra": {},
                    "items": {}
                },
                "morph_ball": {
                    "name": "Morph Ball Door",
                    "extra": {},
                    "items": {}
                },
                "other": {
                    "name": "Other",
                    "extra": {},
                    "items": {
                        "Open Passage": {
                            "lock_type": 0,
                            "extra": {},
                            "requirement": {
                                "type": "and",
                                "data": {
                                    "comment": None,
                                    "items": []
                                }
                            }
                        },
                        "Not Determined": {
                            "lock_type": 0,
                            "extra": {},
                            "requirement": {
                                "type": "or",
                                "data": {
                                    "comment": None,
                                    "items": []
                                }
                            }
                        }
                    }
                }
            },
            "default_weakness": {
                "type": "other",
                "name": "Not Determined"
            }
        },
        "worlds": [{
            "name": "World",
            "extra": {},
            "areas": {
                "Area 1": {
                    "default_node": None,
                    "valid_starting_location": False,
                    "extra": {},
                    "nodes": {
                        "Event - Foo": {
                            "node_type": "generic",
                            "heal": False,
                            "coordinates": None,
                            "description": "",
                            "extra": {},
                            "connections": {
                                "Event - Foo": {
                                    "type": "and",
                                    "data": {
                                        "comment": "",
                                        "items": []
                                    }
                                }
                            }
                        },
                        "Door to Area 2 (Generic)": {
                            "node_type": "dock",
                            "heal": False,
                            "coordinates": None,
                            "description": "",
                            "extra": {},
                            "destination": {
                                "world_name": "World",
                                "area_name": "Area 2",
                                "node_name": "Generic Node"
                            },
                            "dock_type": "other",
                            "dock_weakness": "Open Passage",
                            "connections": {}
                        },
                        "Door to Area 2 (Dock)": {
                            "node_type": "dock",
                            "heal": False,
                            "coordinates": None,
                            "description": "",
                            "extra": {},
                            "destination": {
                                "world_name": "World",
                                "area_name": "Area 2",
                                "node_name": "Door to Area 1"
                            },
                            "dock_type": "other",
                            "dock_weakness": "Open Passage",
                            "connections": {}
                        }
                    }
                },
                "Area 2": {
                    "default_node": "Generic Node",
                    "valid_starting_location": False,
                    "extra": {},
                    "nodes": {
                        "Generic Node": {
                            "node_type": "generic",
                            "heal": False,
                            "coordinates": None,
                            "description": "",
                            "extra": {},
                            "connections": {}
                        },
                        "Door to Area 1": {
                            "node_type": "dock",
                            "heal": False,
                            "coordinates": None,
                            "description": "",
                            "extra": {},
                            "destination": {
                                "world_name": "World",
                                "area_name": "Area 1",
                                "node_name": "Door to Area 2 (Generic)"
                            },
                            "dock_type": "other",
                            "dock_weakness": "Open Passage",
                            "connections": {}
                        }
                    }
                }
            }
        }]
    }
    gd = data_reader.decode_data(sample_data)

    # Run
    errors = integrity_check.find_database_errors(gd)

    # Assert
    assert errors == [
        "World - Area 1 - 'Event - Foo' is not an Event Node, but naming suggests it is",
        "World - Area 1 - Node 'Event - Foo' has a connection to itself",
        "World - Area 1 - 'Door to Area 2 (Generic)' should be named 'Other to Area 2 (...)'",
        "World - Area 1 - 'Door to Area 2 (Generic)' connects to 'world World/area Area 2/node Generic Node'"
        " which is not a DockNode",
        "World - Area 1 - 'Door to Area 2 (Dock)' should be named 'Other to Area 2 (...)'",
        "World - Area 1 - 'Door to Area 2 (Dock)' connects to 'world World/area Area 2/node Door to Area 1',"
        " but that dock connects to 'world World/area Area 1/node Door to Area 2 (Generic)' instead.",
        "World - Area 2 - 'Door to Area 1' should be named 'Other to Area 1'",
        "World - Area 2 - 'Door to Area 1' connects to 'world World/area Area 1/node Door to Area 2 (Generic)',"
        " but that dock connects to 'world World/area Area 2/node Generic Node' instead.",
        "Unknown strongly connected component detected containing 1 nodes:\n"
        "['World/Area 1/Event - Foo']",
        "Unknown strongly connected component detected containing 1 nodes:\n"
        "['World/Area 1/Door to Area 2 (Generic)']",
        "Unknown strongly connected component detected containing 1 nodes:\n"
        "['World/Area 2/Door to Area 1']",
        "Unknown strongly connected component detected containing 1 nodes:\n"
        "['World/Area 1/Door to Area 2 (Dock)']"
    ]