Skip to content

Commit 625c659

Browse files
committed
Rejoice!
1 parent 82ab56b commit 625c659

23 files changed

+671
-239
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
# grid-engine
1+
# grid_engine
22

33
## Description
44

5-
**gridengine** is a framework for generating and manipulating grids. It provides a number of classes and functions for generating and manipulating grids. Each grid is composed of [Cell](#Cell) objects and is defined by a [Blueprint](#Blueprint). A grid can be generated from a blueprint, loaded from a file, or created manually. It can also be pickled for later use. It can be rendered as a 2D image, an animated GIF or an ASCII string. Grids provide a number of relevant methods for pathfinding, cell manipulation, and more.
5+
**grid_engine** is a framework for generating and manipulating grids. It provides a number of classes and functions for generating and manipulating grids. Each grid is composed of [Cell](#Cell) objects and is defined by a [Blueprint](#Blueprint). A grid can be generated from a blueprint, loaded from a file, or created manually. It can also be pickled for later use. It can be rendered as a 2D image, an animated GIF or an ASCII string. Grids provide a number of relevant methods for pathfinding, cell manipulation, and more.
66

77
## Installation
88

9-
To install **gridengine**, run the following command:
9+
To install **grid_engine**, run the following command:
1010

1111
```bash
12-
pip install grid_engine
12+
pip install gridengine_framework
1313
```
1414

1515
## Usage
1616

17-
To use **gridengine** you can import any number of the submodules and utilize its respective features.
17+
To use **gridengine** you can import any number of the submodules and utilize its respective features or you can import the main module.
1818

1919
```python
20-
import gridengine
21-
from gridengine import grid
20+
import grid_engine as ge
2221

2322
# Create a grid
24-
grid = grid.Grid(cell_size=10, grid_dimensions=(1000, 1000))
23+
grid = ge.grid.Grid(cell_size=10, grid_dimensions=(1000, 1000))
2524

2625
# Save a grid
27-
grid.save_grid()
26+
ge.grid.save_grid(grid)
2827

2928
# Load a grid
30-
loaded_grid = grid.Grid.load_grid(1)
29+
loaded_grid = ge.grid.Grid.load_grid(1)
3130
```
3231

33-
grid-engine also provides a command line interface. To use it, run the following command:
32+
**grid_engine** also provides a command line interface. To use it, run the following command:
3433

3534
```bash
3635
python -m grid_engine --help
@@ -63,9 +62,9 @@ grid-engine also provides a command line interface. To use it, run the following
6362
# -v, --verbose Verbose output
6463
```
6564

66-
# Examples
65+
## Examples
6766

68-
The following examples demonstrate the use of the grid-engine package.
67+
The following examples demonstrate the use of the **grid_engine** package.
6968

7069
### CLI
7170

@@ -124,13 +123,14 @@ Will produce the following output:
124123

125124
The following image is the result of the above command:
126125

127-
![grid](grid_engine/_saves/8d564/grid.png)
126+
![grid](saves/cf1b9/grid.png)
127+
128128
*The river generation algorithm is not perfect. I am currently working on improving it.*
129129

130130
The above command will also produce the following files(Not included in the repository... That is, generate your own!):
131131

132-
* `grid.8d564.pickle`: A pickled Grid object.
133-
* `blueprint.8d564.pickle`: A pickled TerrainGridBlueprint object.
132+
* `grid.cf1b9.pickle`: A pickled Grid object.
133+
* `blueprint.cf1b9.pickle`: A pickled TerrainGridBlueprint object.
134134

135135
```python
136136
import grid_engine

grid_engine/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Grid
22

3-
The **Grid** submodule provides numerous classes and functions for generating and manipulating grids. Each grid is composed of [Cell](_cell/cell.py) objects and is defined by a [Blueprint](_blueprint/_grid_blueprint.py). A grid can be generated from a blueprint, loaded from a file, or created manually. It can also be pickled for later use. It cab be rendered as a 2D image, an animated GIF or an ASCII string. Grids provide a number of relevant methods for pathfinding, cell manipulation, and more.
3+
The **Grid** submodule provides numerous classes and functions for generating and manipulating grids. Each grid is composed of [Cell](_cell/_cell.py) objects and is defined by a [Blueprint](_blueprint/_grid_blueprint.py). A grid can be generated from a blueprint, loaded from a file, or created manually. It can also be pickled for later use. It cab be rendered as a 2D image, an animated GIF or an ASCII string. Grids provide a number of relevant methods for pathfinding, cell manipulation, and more.
44

55
## Usage
66

@@ -11,7 +11,7 @@ import gridengine
1111
from gridengine import Grid
1212

1313
# Create a grid
14-
grid = Grid(cell_size=2, grid_dimensi1ons=(5000, 2500))
14+
grid = Grid(cell_size=2, grid_dimensi1ons=(1000, 1000))
1515

1616
# Save a grid
1717
Grid.save_grid(grid)

grid_engine/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from . import _blueprint as blueprint
33
from . import _cell as cell
44
from . import _grid_object as grid_object
5+
# from . import _dungeon as dungeon
56

67
def create_grid(cell_size=None, dimensions=None):
78
if cell_size is None:

grid_engine/__main__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
args = parser.parse_args()
3333

34-
saves_dir = f'{os.path.abspath(os.path.curdir)}grid_engine/_saves/'
34+
saves_dir = f'{os.path.abspath(os.path.curdir)}/saves/'
3535

3636
if not args.verbose:
3737
def print(*args):
@@ -68,29 +68,30 @@ def print(*args):
6868
blueprint.save_blueprint(blueprint=bp)
6969
print('Success!')
7070

71+
72+
73+
cdata = grid.extract_cell_data(g)
74+
cell_size = g.cell_size
75+
grid_id = g.grid_id[-5:]
76+
height = g.blueprint.grid_height
77+
width = g.blueprint.grid_width
78+
del blueprint
79+
80+
from grid_engine import _utility as utility
81+
7182
if args.ascii:
7283
print('Writing ascii to file ...')
73-
with open(f'{saves_dir}{g.grid_id[-5:]}/grid.txt', 'w') as f:
84+
with open(f'{saves_dir}{grid_id}/grid.txt', 'w') as f:
7485
rows = []
7586
string = ''
76-
for row in grid.rows:
87+
for row in g.rows:
7788
for cell in row:
7889
string += cell.terrain_char
7990
rows.append(string)
8091
string = ''
8192
f.write('\n'.join(rows))
8293
print('Success!')
8394

84-
cdata = grid.extract_cell_data(g)
85-
cell_size = g.cell_size
86-
grid_id = g.grid_id[-5:]
87-
height = g.blueprint.grid_height
88-
width = g.blueprint.grid_width
89-
del blueprint
9095
del g
9196

92-
from grid_engine import _utility as utility
93-
9497
utility.generate_images((width, height), cdata, cell_size, grid_id, animate=args.animate)
95-
96-

grid_engine/_blueprint/_grid_blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def _init(self):
368368
self.array[:, :, 0] = self.dictGrid.values()
369369
if not self.with_terrain:
370370
self.dictTerrain = {
371-
cell: {'raw': 1, 'int': 1, 'str': 'GRASS', 'color': _COLORS['GRASS'], 'cost_in': 1, 'cost_out': 1,
371+
cell: {'raw': 1, 'int': 1, 'str': 'GRASS', 'color': _COLORS['GRASS_GREEN'], 'cost_in': 1, 'cost_out': 1,
372372
'char': ''} for cell in self.cell_list}
373373

374374
def _init_quadrants(self):

grid_engine/_blueprint/_grid_processing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def get_cell_coordinates(cell_size: int, row_count: int, col_count: int) -> List
123123
# Output: [(0, 0), (10, 0), (20, 0), (30, 0), (0, 10), (10, 10), (20, 10), (30, 10), (0, 20), (10, 20), (20, 20), (30, 20)]
124124
```
125125
"""
126+
print(f'Getting cell coordinates')
126127
return [
127128
(
128129
abs(0 - ((num % col_count) * cell_size)),
@@ -173,7 +174,8 @@ def get_grid_dict(cell_strings: List[str], row_strings: List[str], col_strings:
173174
"col_index": col_strings.index(cell[-5:]),
174175
"coordinates": cell_coordinates[i],
175176
"quadrant_index": None,
176-
"adjacent": []
177+
"adjacent": [],
178+
"passable": True
177179
} for i, cell in enumerate(cell_strings)
178180
}
179181

@@ -269,6 +271,8 @@ def generate_adjacency(grid_dict: Dict[str, any], row_count: int, col_count: int
269271
h = row_count
270272
for cell, information in grid_dict.items():
271273
print(f'Progress: {information["cell_index"]}/{len(grid_dict)}', end='\r')
274+
if information['cell_index'] == row_count * col_count - 1:
275+
print('\nAdjacency generation complete.')
272276
n = information['cell_index']
273277
r = grid_dict[cell]['row_index']
274278
f = grid_dict[cell]['col_index']

grid_engine/_blueprint/_terrain_processing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'OCEAN_BLUE': (16, 78, 139, 255),
1212
'BARREN_BROWN': (77, 88, 77, 255),
1313
'GRASS_GREEN': (84, 139, 84, 255),
14+
'FOREST_GREEN': (55, 201, 99, 255),
1415
'PLAIN_GREEN': (90, 154, 90, 255),
1516
'FOOTHILL_GREEN': (82, 144, 78, 255),
1617
'GULCH_GREEN': (74, 130, 70, 255),

grid_engine/_cell/README.md

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,151 @@
11
# Cell
22

3-
The Cell class is debatably the most important element of grid-engine. It is integral in the creation of the grid, and is the main way to interact with the grid. The Cell class contains information, which independently is not very useful, but upon arrangement with other cells, can be used to create a whole world.
3+
The Cell class is demonstrably the most important element of `grid-engine`. It is integral in the creation and interaction of the grid. The Cell class contains information which upon arrangement with other cells, can be used to create living world. Cells should never be instantiated directly, but rather through an instance of the `grid_engine.grid.Grid` object. Instances of Cell may then be accessed through said instance.
4+
5+
## Base Properties
6+
7+
The following properties are present in all cell objects:
8+
9+
- `cell_index` (int): The index of the cell in the grid. This serves as a unique identifier for the cell. Cells are indexed from 0 to `grid.size - 1`. With the first cell, `a00001`(index 0) in the top left corner and the last cell, in the bottom right corner.
10+
- `x` (int): The x-coordinate of the cell.
11+
- `y` (int): The y-coordinate of the cell.
12+
- `coordinates` (tuple): The coordinates of the cell in the form `(x, y)`.
13+
- `designation` (str): The designation of the cell. (e.g., 'a00001', 'R0132', etc.)
14+
- `height` (int): The visual height of the cell.
15+
- `width` (int): The visual width of the cell.
16+
- `size` (int): The visual size of the cell.
17+
- `row` (list): The row in which the cell resides, represented as a list of `Cell` objects.
18+
- `row_name` (str): The name of the row in which the cell resides. (e.g., 'a', 'R', etc.)
19+
- `row_index` (int): The index of the row in which the cell resides.
20+
- `col` (list): The col(umn) in which the cell resides, represented as a list of `Cell` objects.
21+
- `col_name` (str): The name of the column in which the cell resides. (e.g., '00395')
22+
- `col_index` (int): The index of the column in which the cell resides.
23+
- `quadrant` (list): The quadrant in which the cell resides, represented as a list of `Cell` objects.
24+
- `quadrant_index` (int): The index of the quadrant in which the cell resides.
25+
- `adjacent` (list): A list of all the cells adjacent to the current cell.
26+
- `up` (Cell): The cell directly above the current cell.
27+
- `down` (Cell): The cell below the current cell.
28+
- `left` (Cell): The cell to the left of the current cell.
29+
- `right` (Cell): The cell to the right of the current cell.
30+
- `up_left` (Cell): The cell above and to the left of the current cell.
31+
- `up_right` (Cell): The cell above and to the right of the current cell.
32+
- `down_left` (Cell): The cell below and to the left of the current cell.
33+
- `down_right` (Cell): The cell below and to the right of the current cell.
34+
- `array` (numpy.ndarray): The cell and all its relevant properties in the form of a numpy array.
35+
- `cost_in` (int): The cost to enter the cell.
36+
- `cost_out` (int): The cost to exit the cell.
37+
38+
## Secondary Properties
39+
40+
The following properties are present in cell objects relating to terrain data:
41+
42+
- `terrain_str` (str): The string representation of the terrain type (`GRASS`, `OCEAN`, etc.).
43+
- `terrain_raw` (float): The raw value of the terrain usually between 0 and 1, generated by a noise function.
44+
- `terrain_int` (int): The integer value of the terrain, corresponding to a specific terrain type.
45+
- `terrain_color` (tuple): The color of the terrain in RGB format, providing the grid is a graphical generation.
46+
- `terrain_char` (str): The ASCII character representing the terrain, in the event of a grid being rendered with `curses` or similar.
47+
- `terrain_shape` [DEPRECATED] (str): The shape of the object representing the cell/terrain. Will be removed in future versions.
48+
- `clearance_up` (int): The clearance above the cell (i.e., the distance between the cell and the nearest above cell that is not passable).
49+
- `clearance_down` (int): The clearance below the cell.
50+
- `clearance_left` (int): The clearance to the left of the cell.
51+
- `clearance_right` (int): The clearance to the right of the cell.
52+
- `clearance_x` (int): The clearance on the x-axis of the cell(i.e., left and right).
53+
- `clearance_y` (int): The clearance on the y-axis of the cell(i.e., up and down).
54+
- `in_region` (bool): Whether the cell is in any region.
55+
- `landmass_index`: The index of the landmass to which the cell belongs.
56+
- `body_of_water_index`: The index of the body of water to which the cell belongs.
57+
- `is_coastal`: Whether the cell is coastal, this includes the coast of oceans or lakes.
58+
59+
## Tertiary Properties
60+
61+
The following properties are related to the values stored in the `array` property. They are prefixed with the word `entry`.
62+
Accessing and modifying these properties will be reflected in the `array` property and vice versa. Most of these properties have convenient methods for accessing and modifying them. For example, the `add_object` method can be used to add an object to the cell, thereby modifying the `entry_object` property and the `array` property.
63+
64+
- `entry` (array): A dictionary containing the base properties of the cell. This includes the following properties:
65+
- `designation` (str)
66+
- `cell_index` (int)
67+
- `row_index` (int)
68+
- `col_index` (int)
69+
- `ooordinates` (tuple)
70+
- `quadrant_index` (int)
71+
- `adjacent` (list)
72+
- `passable` (bool)
73+
- `entry_terrain` (dict): A dictionary containing the terrain information for the cell. This includes the following properties:
74+
- `terrain_str` (str)
75+
- `terrain_raw` (float)
76+
- `terrain_int` (int)
77+
- `terrain_color` (tuple)
78+
- `terrain_char` (str)
79+
- `terrain_shape` (str)
80+
- `entry_object` (dict): A dictionary containing the objects which may currently exist on the cell. This includes the following properties:
81+
- `items` (dict)
82+
- `obstructions` (dict)
83+
- `structures` (dict)
84+
- `features` (dict)
85+
- `resources` (dict)
86+
- `containers` (dict)
87+
- `doors` (dict)
88+
- `traps` (dict)
89+
- `switches` (dict)
90+
- `entry_unit` (dict): A dictionary containing the units which may currently exist on the cell. This includes the following properties:
91+
- `players` (dict)
92+
- `npcs` (dict)
93+
- `monsters` (dict)
94+
- `neutrals` (dict)
95+
- `pets` (dict)
96+
- `mounts`
97+
- `entry_zone` (dict): A dictionary containing the zones which may currently exist on the cell. This includes the following properties:
98+
- `areas`
99+
- `locales`
100+
- `regions`
101+
- `cities`
102+
- `towns`
103+
- `villages`
104+
- `entry_effect` (dict): A dictionary containing the effects which may currently exist on the cell. This includes the following properties:
105+
- `weather`
106+
- `lighting`
107+
- `environment`
108+
- `magic`
109+
- `entry_fow` (dict): A dictionary containing the fog of war information for the cell. This includes the following properties:
110+
- `visibility`
111+
- `explored`
112+
- `seen`
113+
- `hidden`
114+
115+
## Methods
116+
117+
- `__init__(self, x, y, designation, height, width, row=None, col=None, quadrant=None)`: The constructor for the Cell class.
118+
- `__repr__(self)`: The representation of the cell. For example, 'a00001'.
119+
- `add_object(self, grid_object)`: Adds an object to the cell.
120+
- `add_unit(self, unit)`: Adds a unit to the cell.
121+
- `add_zone(self, zone)`: Adds a zone to the cell.
122+
- `build(self, orientation)`: Constructs a wall-like grid structure on the cell in the specified orientation.
123+
- `dig(self)`: if the cell is unpassable, dig is meant to emulate the removal of said obstacle.
124+
- `get_diagonal(self, xaxis, yaxis, distance)`: Returns a list of cells that are diagonal to the current cell at a specified distance in a specified direction.
125+
- `get_groups(self)`: Returns a list of all the groups to which the cell belongs.
126+
- `get_region(self)`: Returns the region to which the cell belongs.
127+
- `get_clearance_zone(self)` (list): Returns a list of passable cells which surround the current cell.
128+
- `in_neighborhood(self, neighbor)`: Returns True if the cell is in the neighborhood of the specified cell.
129+
- `join_group(self, group)`: Adds the cell to the specified group.
130+
- `leave_group(self, group)`: Removes the cell from the specified group.
131+
- `on_construct(self)`: A method that is called when a construction is completed on the cell.
132+
- `on_destruct(self)`: A method that is called when a destruction is completed on the cell.
133+
- `on_divest(self)`: Sets the cell as unentitled.
134+
- `on_entitle(self)`: Sets the cell as entitled.
135+
- `on_occupy(self)`: A method that is called when a cell becomes occupied.
136+
- `on_vacate(self)`: A method that is called when a cell is no longer occupied.
137+
- `recv_occupant(self, occupant)`: Receives an occupant signal from a GridEntity.
138+
- `remove_object(self, grid_object)`: Removes an object from the cell.
139+
- `remove_unit(self, unit)`: Removes a unit from the cell.
140+
141+
## Usage
142+
143+
```python
144+
import grid_engine as ge
145+
146+
grid = ge.grid.Grid()
147+
148+
cell = grid.random_cell()
149+
150+
print(cell)
151+
```

grid_engine/_cell/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .cell import Cell
1+
from ._cell import Cell

0 commit comments

Comments
 (0)