Empeld
Empeld plugin documentation.
essentials.Prefabs.PrefabConstructor Class Reference

A helper object that will keep a list of blocks to-be-constructed in the world More...

Public Member Functions

 PrefabConstructor (IWorld world, IEnumerable< PrefabBlock > buildList)
 Initializes a new instance of the essentials.Prefabs.PrefabConstructor class. More...
 
PrefabBlock Peek ()
 Gets the next block to be constructed, if any More...
 
PrefabBlock Pop ()
 Pops the next block to be constructed of the queue, if any More...
 
bool BuildNext ()
 Pop the next block off the stack and build it in the world More...
 
void Construct ()
 Build the entire construct in the world More...
 
ITask CreateScheduledTask (TimeSpan placeDelay)
 Helper to create a scheduled task to build the structure over time More...
 

Properties

bool Complete [get]
 Has the construction completed More...
 

Detailed Description

A helper object that will keep a list of blocks to-be-constructed in the world

Constructor & Destructor Documentation

◆ PrefabConstructor()

essentials.Prefabs.PrefabConstructor.PrefabConstructor ( IWorld  world,
IEnumerable< PrefabBlock buildList 
)

Initializes a new instance of the essentials.Prefabs.PrefabConstructor class.

Parameters
worldWorld.
buildListBuild list.
33  {
34  _world = world;
35  _enumerator = buildList.GetEnumerator();
36  if (!_enumerator.MoveNext())
37  _enumerator = null; //There's nothing actually in the enumerator
38  }

Member Function Documentation

◆ BuildNext()

bool essentials.Prefabs.PrefabConstructor.BuildNext ( )

Pop the next block off the stack and build it in the world

Returns
true, if next was built, false otherwise.

Attribute: item.Value.WorldPos].Block = _world.BlockLookup[item.Value.Block.Id

;

71  {
72  var item = this.Pop();
73  if (item.HasValue)
74  {
75  _world[item.Value.WorldPos].Block = _world.BlockLookup[item.Value.Block.Id];
76  return true;
77  }
78  return false;
79  }
PrefabBlock Pop()
Pops the next block to be constructed of the queue, if any
Definition: PrefabConstructor.cs:53

◆ Construct()

void essentials.Prefabs.PrefabConstructor.Construct ( )

Build the entire construct in the world

85  {
86  while (this.BuildNext())
87  { }
88  }
bool BuildNext()
Pop the next block off the stack and build it in the world
Definition: PrefabConstructor.cs:70

◆ CreateScheduledTask()

ITask essentials.Prefabs.PrefabConstructor.CreateScheduledTask ( TimeSpan  placeDelay)

Helper to create a scheduled task to build the structure over time

Returns
The scheduled task.
Parameters
placeDelayPlace delay.
96  {
97  return new RecurringTask(() => {
98  return this.BuildNext() ? TaskResult.Continue : TaskResult.Remove;
99  }, placeDelay);
100  }
Recurring task. Returns true once done
Definition: RecurringTask.cs:8
bool BuildNext()
Pop the next block off the stack and build it in the world
Definition: PrefabConstructor.cs:70
TaskResult
The result of a scheduled task
Definition: TaskResult.cs:8

◆ Peek()

PrefabBlock essentials.Prefabs.PrefabConstructor.Peek ( )

Gets the next block to be constructed, if any

44  {
45  if (_enumerator == null)
46  return null;
47  return _enumerator.Current;
48  }

◆ Pop()

PrefabBlock essentials.Prefabs.PrefabConstructor.Pop ( )

Pops the next block to be constructed of the queue, if any

54  {
55  if (_enumerator == null)
56  return null;
57 
58  var curr = _enumerator.Current;
59 
60  if (!_enumerator.MoveNext())
61  _enumerator = null;
62 
63  return curr;
64  }

Property Documentation

◆ Complete

bool essentials.Prefabs.PrefabConstructor.Complete
get

Has the construction completed

true if complete; otherwise, false.


The documentation for this class was generated from the following file: