Skip to content

Commit 09fa649

Browse files
more backend work
1 parent e13f044 commit 09fa649

29 files changed

+1136
-217
lines changed

dub.sdl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ dependency "dcontain" version="~>1.0.3"
88
dependency "gtk-d" version="~>3.9.0"
99
dependency "wsf" version="~master"
1010
dependency "d-dazzle" version="~>1.0.1"
11-
dependency "ppc" version="~>0.2.6"
11+
dependency "ppc" version="~>0.3.0"
1212
stringImportPaths "res/" "stylesheets/"

source/wsedit/ir/package.d

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module wsedit.ir;
2+
public import wsedit.ir.scene;

source/wsedit/ir/scene.d

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
module wsedit.ir.scene;
2+
import wsedit.math;
3+
4+
/**
5+
A scene
6+
*/
7+
class Scene {
8+
public:
9+
this() { }
10+
11+
/**
12+
Creates a new scene
13+
*/
14+
this(string name, string path, Vector2i tileSize) {
15+
this.name = name;
16+
this.path = path;
17+
this.tileSize = tileSize;
18+
}
19+
20+
/// Name of scene
21+
string name;
22+
23+
/// Output file name
24+
string path;
25+
26+
/// The size of all tiles
27+
Vector2i tileSize;
28+
29+
/// Regions of the scene
30+
Region[] regions;
31+
32+
/// The currently selected region
33+
uint selectedRegion = 0;
34+
}
35+
36+
/**
37+
A region
38+
*/
39+
class Region {
40+
private:
41+
Scene parent;
42+
bool overlapFlag;
43+
44+
public:
45+
this(Scene parent) {
46+
this.parent = parent;
47+
}
48+
49+
this(Scene parent, Rectangle area) {
50+
this(parent);
51+
mainLayer = new Layer(area);
52+
bgLayer = new Layer(area);
53+
colLayer = new Layer(area);
54+
this.resize(area);
55+
this.scanOverlaps();
56+
}
57+
58+
/**
59+
The area of the region
60+
*/
61+
Rectangle area;
62+
63+
/**
64+
Resize the region, updating the layers' sizes
65+
*/
66+
void resize(Rectangle area) {
67+
this.area = area;
68+
mainLayer.resize(area);
69+
bgLayer.resize(area);
70+
}
71+
72+
/**
73+
The main layer (drawn infront of player)
74+
*/
75+
Layer mainLayer;
76+
77+
/**
78+
Background layer
79+
*/
80+
Layer bgLayer;
81+
82+
/**
83+
Collission layer
84+
*/
85+
Layer colLayer;
86+
87+
/**
88+
Parallax objects
89+
*/
90+
ParallaxObject[] parallax;
91+
92+
void scanOverlaps() {
93+
foreach(region; parent.regions) {
94+
if (region == this) continue;
95+
96+
if (area.intersects(region.area) || region.area.intersects(area)) {
97+
overlapFlag = true;
98+
return;
99+
}
100+
}
101+
overlapFlag = false;
102+
}
103+
104+
/**
105+
Returns true if this region is overlapping an other
106+
*/
107+
bool isOverlapping() {
108+
return overlapFlag;
109+
}
110+
}
111+
112+
/**
113+
A region for a camera
114+
*/
115+
class CamRegion {
116+
/**
117+
The area the camera is to stay in
118+
*/
119+
Rectangle area;
120+
121+
/// Allow the camera to move within the region
122+
bool allowMoveWithin;
123+
124+
/// The zoom level to (smoothly) be applied to the camera
125+
double cameraZoom;
126+
}
127+
128+
/**
129+
A parallax scrolling object
130+
*/
131+
class ParallaxObject {
132+
/// The ID of the object's texture
133+
string textureId;
134+
135+
/// The area to render in
136+
Rectangle textureArea;
137+
138+
/// Wether to loop the texture inside its render area
139+
bool loop = false;
140+
141+
/// The depth to draw in, negative = infront of player, positive = behind, 0 = zfighting
142+
int depth;
143+
144+
/// The ratio for parallax scrolling
145+
Vector2 parallaxRatio;
146+
}
147+
148+
/**
149+
A layer
150+
*/
151+
class Layer {
152+
private:
153+
Rectangle area;
154+
155+
public:
156+
157+
/**
158+
Creates an empty layer
159+
*/
160+
this() {}
161+
162+
/**
163+
Creates a new layer with the specified size
164+
*/
165+
this(Rectangle area) {
166+
this.resize(area);
167+
}
168+
169+
/**
170+
Contains tiles
171+
172+
[y][x]
173+
*/
174+
Tile[][] tiles;
175+
176+
/**
177+
Allows indexing with [x, y] coordinate sets
178+
*/
179+
ref Tile opIndex(uint x, uint y) {
180+
return tiles[y][x];
181+
}
182+
183+
/**
184+
Allows iteration via foreach
185+
*/
186+
int opApply(int delegate(ref uint, ref uint, ref Tile) func) {
187+
int result = 0;
188+
for (uint y = 0; y < area.height; y++) {
189+
for (uint x = 0; x < area.width; x++) {
190+
result = func(x, y, this[x, y]);
191+
192+
if (result) break;
193+
}
194+
}
195+
return result;
196+
}
197+
198+
/**
199+
Resizes this layer
200+
*/
201+
void resize(Rectangle area) {
202+
this.area = area;
203+
tiles.length = area.height;
204+
foreach(y; 0..area.height) {
205+
tiles[y].length = area.width;
206+
}
207+
}
208+
}
209+
210+
/**
211+
A tile
212+
*/
213+
class Tile {
214+
/// The ID of the tile
215+
Vector2i tileId;
216+
217+
/// Vertical flip
218+
bool vflip;
219+
220+
/// Horizontal flip
221+
bool hflip;
222+
}
223+
224+
/**
225+
An actor
226+
*/
227+
class Actor {
228+
public:
229+
/// The ID of the actor
230+
string actorId;
231+
232+
233+
}

source/wsedit/math.d

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
module wsedit.math;
2+
3+
/**
4+
A point in 2D space
5+
*/
6+
struct Vector2 {
7+
8+
/**
9+
X coordinate
10+
*/
11+
double x = 0.0;
12+
13+
/**
14+
Y coordinate
15+
*/
16+
double y = 0.0;
17+
}
18+
19+
/**
20+
A point in 2D space
21+
*/
22+
struct Vector2i {
23+
24+
/**
25+
X coordinate
26+
*/
27+
int x = 0;
28+
29+
/**
30+
Y coordinate
31+
*/
32+
int y = 0;
33+
34+
}
35+
36+
/**
37+
A rectangle
38+
*/
39+
struct Rectangle {
40+
/**
41+
X
42+
*/
43+
int x;
44+
45+
/**
46+
Y
47+
*/
48+
int y;
49+
50+
/**
51+
Width
52+
*/
53+
int width;
54+
55+
/**
56+
Height
57+
*/
58+
int height;
59+
60+
/// The left side
61+
int left() { return x; }
62+
63+
/// The right side
64+
int right() { return x+width; }
65+
66+
/// The top
67+
int top() { return y; }
68+
69+
/// The bottom
70+
int bottom() { return y+height; }
71+
72+
/**
73+
Gets wether this rectangle intersects an other Rectangle
74+
*/
75+
bool intersects(Rectangle other) {
76+
return !(
77+
other.left >= this.right ||
78+
other.right <= this.left ||
79+
other.top >= this.bottom ||
80+
other.bottom <= this.top
81+
);
82+
}
83+
84+
/**
85+
Gets wether this rectangle intersects an other Vector
86+
*/
87+
bool intersects(Vector2 other) {
88+
return !(
89+
other.x >= this.right ||
90+
other.x <= this.left ||
91+
other.y >= this.bottom ||
92+
other.y <= this.top
93+
);
94+
}
95+
96+
/**
97+
Gets wether this rectangle intersects an other Vector
98+
*/
99+
bool intersects(Vector2i other) {
100+
return !(
101+
other.x >= this.right ||
102+
other.x <= this.left ||
103+
other.y >= this.bottom ||
104+
other.y <= this.top
105+
);
106+
}
107+
108+
/**
109+
Gets the cetner of this rectangle
110+
*/
111+
Vector2 center() {
112+
return Vector2(cast(double)x+cast(double)(width/2), cast(double)y+cast(double)(height/2));
113+
}
114+
}

0 commit comments

Comments
 (0)