Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
0.1.0
  • Loading branch information
MKaras93 authored Sep 14, 2022
2 parents efadcf0 + 56422e8 commit f0374c3
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 269 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,56 @@ There is a special class representing parent-children relation (one-to-many). It
the relation. For example, when OrbitalStation instance changes its attribute `controlling_faction`, the attribute `stations` on the
FactionBranch instance is also updated, and vice versa. The parent is kept in sync with the children.

# Can I use the classes without external data source?
From now on - Yes! The whole adapter engine has been extracted, so now, apart from full auto-refreshed classes available
in the `classes` module, you can use the "offline" Model classes available in the `models` module.

## Model classes
They represent objects (factions, systems, faciton branches and stations) and keep the relation between them, but they
are static objects, not connected to any external data source. If you use these classes, they will only store the data
you have filled them with. For example. creating a SystemModel of system Sol will no longer let you fetch data about
"Sol" system:

```python
from edclasses.models import SystemModel

sol_model = SystemModel.create(name="Sol")
# the model has the same attributes ed class has, however it will not look for data anywhere else:

print(sol_model.stations)
[]
# A normal instance of System class would at this point query API Adapter for data, but the model doesn't do that.
```

### Advantages
Is there anything special about the model class itself if it doesn't fetch the data? Well, yes - relations. The model
classes are meant to work like a database - keep links between different objects in your program. Look at this example:

```python
>>> from edclasses.models import SystemModel, FactionModel, FactionBranchModel

>>> sol = SystemModel.create(name="Sol")
>>> sol.faction_branches
[]

>>> faction = FactionModel.create(name="Some Faction")
>>> faction.faction_branches
[]

>>> faction_branch = FactionBranchModel.create(faction=faction, system=sol)
# at these point the relations between are updated:

>>> sol.faction_branches
[Some Faction in Sol]

>>> faction.faction_branches
[Some Faction in Sol]
```

How can this be useful? Even though `edlasses` have been designed to be used with the API, maybe you have some idea
to create a whole universe simulation based on a CSV file on some Database of your own? This objects should make it
possible to do so without writing your own classes.

# Where is the data coming from?
The library comes with a simple adapter to a magnificent API at www.elitebgs.app (seriously, they made a great job, you
should check it out if you haven't already).
Expand Down Expand Up @@ -130,5 +180,7 @@ factions of interests. If your app is too data-hungry, it will result in the fol
Yes, the provided EliteBgsApiAdapter is just an example. You can write a similar adapter, or extend this one, and then
connect it to the proper class in edclasses. I will add a more detailed tutorial in the future.

You can also use the model classes (check out ## model classes above) and create your own data source system.

# Why don't you XYZ:
The project is in very early phase. Have any idea? Please open an issue, I would be glad to discuss.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "elite-dangerous-classes-library"
version = "0.0.6"
version = "0.1.0"
description = "Library representing various objects in Elite Dangerous"
readme = "README.md"
authors = [{ name = "Michał Karaś", email = "mjkaras93@gmail.com" }]
Expand Down
2 changes: 1 addition & 1 deletion src/edclasses/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .classes import *
from .classes import System, OrbitalStation, Faction, FactionBranch
23 changes: 15 additions & 8 deletions src/edclasses/api_adapters/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from decimal import Decimal

import edclasses
# TODO: Fix ugly imports


def get_orbital_station(
Expand All @@ -11,14 +11,15 @@ def get_orbital_station(
services=None,
controlling_faction=None,
):
from edclasses import System, OrbitalStation

if isinstance(system, str):
system = edclasses.System.create(name=system)
system = System.create(name=system)

if distance_to_arrival and not isinstance(distance_to_arrival, Decimal):
distance_to_arrival = Decimal(distance_to_arrival)

return edclasses.OrbitalStation.create(
return OrbitalStation.create(
name=name,
station_type=station_type,
system=system,
Expand All @@ -29,18 +30,24 @@ def get_orbital_station(


def get_faction(name):
return edclasses.Faction.create(name=name)
from edclasses import Faction

return Faction.create(name=name)


def get_faction_branch(faction, system):
from edclasses import System, Faction, FactionBranch

if isinstance(system, str):
system = edclasses.System.create(name=system)
system = System.create(name=system)

if isinstance(faction, str):
faction = edclasses.Faction.create(name=faction)
faction = Faction.create(name=faction)

return edclasses.FactionBranch.create(faction=faction, system=system)
return FactionBranch.create(faction=faction, system=system)


def get_system(name):
return edclasses.System.create(name=name)
from edclasses import System

return System.create(name=name)
Loading

0 comments on commit f0374c3

Please sign in to comment.