hd2api.builders package

Submodules

hd2api.builders.assignment_builder module

hd2api.builders.assignment_builder.build_all_assignments(assignments: List[Assignment]) List[Assignment2]

Given a list of raw Assignment objects, return a list of Assignment2.

Parameters:

assignments (List[Assignment]) – List of raw Assignment objects.

Returns:

A list of transformed assignments.

Return type:

List[Assignment2]

hd2api.builders.assignment_builder.build_assignment_2(assignment: Assignment) Assignment2

Transforms a raw Assignment object into an easier to understand Assignment2 object.

Parameters:
  • assignment (Assignment) – The original assignment object.

  • diveharder (DiveharderAll) – Contextual object containing additional necessary information.

Returns:

The transformed assignment.

Return type:

Assignment2

hd2api.builders.campaign_builder module

hd2api.builders.campaign_builder.build_all_campaigns(planets: Dict[int, Planet], warstatus: WarStatus)

Build a list of Campaign2 objects from the campaigns in the given WarStatus.

Parameters:
  • planets (Dict[int, Planet]) – A dictionary mapping planet IDs to Planet objects.

  • warstatus (WarStatus) – The current WarStatus.

Returns:

A list of Campaign2 objects built from the warstatus campaigns.

Return type:

List[Campaign2]

hd2api.builders.campaign_builder.build_campaign(planets: Dict[int, Planet | None], campaign: Campaign)

Create a new Campaign2 instance based on the given Campaign and planet data.

Parameters:
  • planets (Dict[int, Planet]) – A dictionary mapping planet IDs to Planet objects.

  • campaign (Campaign) – The campaign object that contains the data to create Campaign2.

Returns:

A new campaign object with the associated planet and other data.

Return type:

Campaign2

hd2api.builders.effect_builder module

hd2api.builders.effect_builder.build_planet_effect(static_effects: EffectStatic, idv: int) KnownPlanetEffect

Given a static representation of all known planet effects with their ids, retrieve the known planet effect if it exists.

Parameters:
  • static_effects (EffectStatic) – The static representation containing all known effects generated from the json files in ./statics

  • idv (int) – The ID of the planet effect to retrieve.

Returns:

A known planet effect with a matching id; otherwise, a Newly created KnownPlanetEffect indicating the effect is unknown.

Return type:

KnownPlanetEffect

hd2api.builders.planet_builder module

hd2api.builders.planet_builder.build_all_planets(warall: DiveharderAll, statics: StaticAll) Dict[int, Planet]

Builds a dictionary of all planets by iterating over the galaxy’s static planet data and invoking build_planet_2 for each planet.

Parameters:
  • warall (DiveharderAll) – Operational game state and status data.

  • statics (StaticAll) – Static information about the game’s universe.

Returns:

A dictionary mapping planet indices to Planet objects.

Return type:

dict

hd2api.builders.planet_builder.build_planet_2(planetIndex: int, warall: DiveharderAll, statics: StaticAll)

Constructs a Planet object for a given planetIndex by associating the respective PlanetStatus, PlanetInfo, PlanetStats, PlanetEffects, PlanetAttacks, and PlanetEvents from a DiveharderAll object and the static galaxy details.

Parameters:
  • planetIndex (int) – The index of the planet to be constructed.

  • warall (DiveharderAll) – Operational game state and status data.

  • statics (StaticAll) – Static game universe information.

Returns:

The constructed Planet object for the specified index.

Return type:

Planet

hd2api.builders.planet_builder.build_planet_basic(gstatic: GalaxyStatic, index: int, planetStatus: PlanetStatus, planetInfo: PlanetInfo, stats: PlanetStats) Planet

Builds a new Planet object using the provided GalaxyStatic, PlanetStatus, PlanetInfo, and PlanetStats fields.

Parameters:
  • gstatic (GalaxyStatic) – The static information about planets, enviornmental effects, and biomes in the galaxy

  • index (int) – Index of the planet within the galaxy.

  • planetStatus (PlanetStatus) – The Raw PlanetStatus object with a matching index.

  • planetInfo (PlanetInfo) – The raw PlanetInfo object with a matching index

  • stats (PlanetStats) – The Game Statistics for the planet.

Returns:

The newly constructed Planet object or None if the planet doesn’t exist in the provided galaxy static information.

Return type:

Planet

hd2api.builders.planet_builder.build_planet_full(planetIndex: int, status: WarStatus, info: WarInfo, summary: WarSummary, statics: StaticAll, regions: List[Region] | None = None) Planet

Constructs a Planet object for a given planetIndex by associating the respective PlanetStatus, PlanetInfo, PlanetStats, PlanetEffects, PlanetAttacks, and PlanetEvents from the WarStatus, WarInfo, and WarSummary data obtained from the API, along with the static galaxy details.

Parameters:
  • planetIndex (int) – The index of the planet to be constructed.

  • status (WarStatus) – Current state and status of the war.

  • info (WarInfo) – Information related to the ongoing war.

  • summary (WarSummary) – Summary statistics and data associated with the war.

  • statics (StaticAll) – Static game universe information.

Returns:

The constructed Planet object for the specified index.

Return type:

Planet

hd2api.builders.planet_builder.check_compare_value(key, value, target: List[Dict[str, Any]])
hd2api.builders.planet_builder.check_compare_value_list(keys: List[str], values: List[Any], target: List[Dict[str, Any]])
hd2api.builders.planet_builder.generate_planet_name(seed) str

Novelty. Make up a planet name if it doesn’t exist.

hd2api.builders.planet_builder.get_time(status: WarStatus, info: WarInfo) datetime

get the relative start of the war according the game’s internal “time” value

hd2api.builders.planet_builder.get_time_dh(diveharder: DiveharderAll) datetime

get the relative start of the war according the game’s internal “time” value using DiveharderAll

hd2api.builders.region_builder module

hd2api.builders.region_builder.build_all_regions(warall: DiveharderAll, statics: StaticAll) List[Region]

Merges all PlanetRegion and PlanetRegionInfo entries into Region objects.

Returns:

All fully merged region statuses.

Return type:

List[Region]

hd2api.builders.region_builder.build_region(region: PlanetRegion, region_info: PlanetRegionInfo, statics: StaticAll) Region | None

Builds a Region object from PlanetRegion, PlanetRegionInfo, and static data.

Parameters:
  • region (PlanetRegion) – Dynamic state of the region.

  • region_info (PlanetRegionInfo) – Static info/config of the region.

  • statics (StaticAll) – Game-wide static data, used for name/description.

Returns:

A fully merged Region or None if static data not found.

Return type:

Optional[Region]

hd2api.builders.sector_state_builder module

hd2api.builders.sector_state_builder.sector_states(war_status: WarStatus, statics: StaticAll) List[SectorStates]

Organizes planetary war status by sector.

Parameters:
  • war_status (WarStatus) – An object containing the current war status, including a list of planet statuses.

  • statics (StaticAll) – An object containing static data, including galaxy and planet information.

Returns:

A list of SectorStates objects, each representing the war status of a sector.

Return type:

list[SectorStates]

hd2api.builders.statistics_builder module

hd2api.builders.statistics_builder.statistics_builder(stats: PlanetStats | GalaxyStats, players: int, retrieved_at: datetime | None = None) Statistics

Build a Statistics object.

Parameters:
  • stats (Union[PlanetStats, GalaxyStats]) – Raw object containing statistics data for either a planet or galaxy.

  • players (int) – The number of players involved.

  • retrieved_at (Optional[dt]) – The time at which the statistics were retrieved. If not provided, the time will be taken from the stats object.

Returns:

A Statistics object with the compiled data.

Return type:

Statistics

hd2api.builders.war_builder module

hd2api.builders.war_builder.build_war(diveharder: DiveharderAll) War

Module contents

hd2api.builders.build_all_assignments(assignments: List[Assignment]) List[Assignment2]

Given a list of raw Assignment objects, return a list of Assignment2.

Parameters:

assignments (List[Assignment]) – List of raw Assignment objects.

Returns:

A list of transformed assignments.

Return type:

List[Assignment2]

hd2api.builders.build_all_campaigns(planets: Dict[int, Planet], warstatus: WarStatus)

Build a list of Campaign2 objects from the campaigns in the given WarStatus.

Parameters:
  • planets (Dict[int, Planet]) – A dictionary mapping planet IDs to Planet objects.

  • warstatus (WarStatus) – The current WarStatus.

Returns:

A list of Campaign2 objects built from the warstatus campaigns.

Return type:

List[Campaign2]

hd2api.builders.build_all_planets(warall: DiveharderAll, statics: StaticAll) Dict[int, Planet]

Builds a dictionary of all planets by iterating over the galaxy’s static planet data and invoking build_planet_2 for each planet.

Parameters:
  • warall (DiveharderAll) – Operational game state and status data.

  • statics (StaticAll) – Static information about the game’s universe.

Returns:

A dictionary mapping planet indices to Planet objects.

Return type:

dict

hd2api.builders.build_all_regions(warall: DiveharderAll, statics: StaticAll) List[Region]

Merges all PlanetRegion and PlanetRegionInfo entries into Region objects.

Returns:

All fully merged region statuses.

Return type:

List[Region]

hd2api.builders.build_campaign(planets: Dict[int, Planet | None], campaign: Campaign)

Create a new Campaign2 instance based on the given Campaign and planet data.

Parameters:
  • planets (Dict[int, Planet]) – A dictionary mapping planet IDs to Planet objects.

  • campaign (Campaign) – The campaign object that contains the data to create Campaign2.

Returns:

A new campaign object with the associated planet and other data.

Return type:

Campaign2

hd2api.builders.build_planet_2(planetIndex: int, warall: DiveharderAll, statics: StaticAll)

Constructs a Planet object for a given planetIndex by associating the respective PlanetStatus, PlanetInfo, PlanetStats, PlanetEffects, PlanetAttacks, and PlanetEvents from a DiveharderAll object and the static galaxy details.

Parameters:
  • planetIndex (int) – The index of the planet to be constructed.

  • warall (DiveharderAll) – Operational game state and status data.

  • statics (StaticAll) – Static game universe information.

Returns:

The constructed Planet object for the specified index.

Return type:

Planet

hd2api.builders.build_planet_basic(gstatic: GalaxyStatic, index: int, planetStatus: PlanetStatus, planetInfo: PlanetInfo, stats: PlanetStats) Planet

Builds a new Planet object using the provided GalaxyStatic, PlanetStatus, PlanetInfo, and PlanetStats fields.

Parameters:
  • gstatic (GalaxyStatic) – The static information about planets, enviornmental effects, and biomes in the galaxy

  • index (int) – Index of the planet within the galaxy.

  • planetStatus (PlanetStatus) – The Raw PlanetStatus object with a matching index.

  • planetInfo (PlanetInfo) – The raw PlanetInfo object with a matching index

  • stats (PlanetStats) – The Game Statistics for the planet.

Returns:

The newly constructed Planet object or None if the planet doesn’t exist in the provided galaxy static information.

Return type:

Planet

hd2api.builders.build_planet_effect(static_effects: EffectStatic, idv: int) KnownPlanetEffect

Given a static representation of all known planet effects with their ids, retrieve the known planet effect if it exists.

Parameters:
  • static_effects (EffectStatic) – The static representation containing all known effects generated from the json files in ./statics

  • idv (int) – The ID of the planet effect to retrieve.

Returns:

A known planet effect with a matching id; otherwise, a Newly created KnownPlanetEffect indicating the effect is unknown.

Return type:

KnownPlanetEffect

hd2api.builders.build_region(region: PlanetRegion, region_info: PlanetRegionInfo, statics: StaticAll) Region | None

Builds a Region object from PlanetRegion, PlanetRegionInfo, and static data.

Parameters:
  • region (PlanetRegion) – Dynamic state of the region.

  • region_info (PlanetRegionInfo) – Static info/config of the region.

  • statics (StaticAll) – Game-wide static data, used for name/description.

Returns:

A fully merged Region or None if static data not found.

Return type:

Optional[Region]

hd2api.builders.build_war(diveharder: DiveharderAll) War
hd2api.builders.get_time(status: WarStatus, info: WarInfo) datetime

get the relative start of the war according the game’s internal “time” value

hd2api.builders.get_time_dh(diveharder: DiveharderAll) datetime

get the relative start of the war according the game’s internal “time” value using DiveharderAll

hd2api.builders.sector_states(war_status: WarStatus, statics: StaticAll) List[SectorStates]

Organizes planetary war status by sector.

Parameters:
  • war_status (WarStatus) – An object containing the current war status, including a list of planet statuses.

  • statics (StaticAll) – An object containing static data, including galaxy and planet information.

Returns:

A list of SectorStates objects, each representing the war status of a sector.

Return type:

list[SectorStates]

hd2api.builders.statistics_builder(stats: PlanetStats | GalaxyStats, players: int, retrieved_at: datetime | None = None) Statistics

Build a Statistics object.

Parameters:
  • stats (Union[PlanetStats, GalaxyStats]) – Raw object containing statistics data for either a planet or galaxy.

  • players (int) – The number of players involved.

  • retrieved_at (Optional[dt]) – The time at which the statistics were retrieved. If not provided, the time will be taken from the stats object.

Returns:

A Statistics object with the compiled data.

Return type:

Statistics