-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorldGenerator.cs
executable file
·85 lines (72 loc) · 1.91 KB
/
WorldGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
public class WorldGenerator
{
private List<GeneratorStep> Steps;
public readonly World MyWorld;
public bool Finished
{
get;
private set;
}
public WorldGenerator(World w)
{
Steps = new List<GeneratorStep>();
MyWorld = w;
Finished = false;
}
public void AddStep(GeneratorStep step)
{
if (!Steps.Contains(step))
{
Steps.Add(step);
}
}
public GeneratorStep GetStep(string name)
{
foreach (GeneratorStep step in Steps)
{
if (step.Name == name)
{
return step;
}
}
return null;
}
public void Run(int seed)
{
int stepsLeft = Steps.Count;
while (stepsLeft > 0)
{
bool stepThisRun = false;
foreach (GeneratorStep step in Steps)
{
if (step.CanRun())
{
Console.WriteLine("Applying step "+step.Name);
step.Apply(MyWorld, seed);
stepsLeft--;
stepThisRun = true;
if (stepsLeft == 0)
{
return;
}
}
}
if (!stepThisRun)
{
Finished = true;
throw new InvalidOperationException("Ran out of steps while world generation was still running");
}
}
Finished = true;
}
public void Reset()
{
foreach (GeneratorStep step in Steps)
{
step.Finished = false;
}
Finished = false;
}
}