summaryrefslogtreecommitdiffhomepage
path: root/spec/stage_manager_spec.rb
blob: 0aa8690735ec5beb4140476dabaed50409775eb9 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require_relative '../lib/felflame.rb'

#class EntitiesTest < Minitest::Test

describe 'Stage' do
  before :all do
    @component_manager ||= FelFlame::Components.new('TestStage', order: Array.new)
    @system2 = FelFlame::Systems.new('StageTest', priority: 50) do
      @component_manager.each do |component|
        component.order.push 2
      end
    end
    @system1 = FelFlame::Systems.new('StageMana', priority: 1) do
      @component_manager.each do |component|
        component.order.push 1
      end
    end
    @system3 = FelFlame::Systems.new('StageSpell', priority: 100) do
      @component_manager.each do |component|
        component.order.push 3
      end
    end
    @scene1 = FelFlame::Scenes.new('TestStage1')
    @scene2 = FelFlame::Scenes.new('TestStage2')
    @scene3 = FelFlame::Scenes.new('TestStage3')
  end

  before :each do
    @cmp = @component_manager.new
    @scene1.add @system1
    @scene2.add @system2
    @scene3.add @system3
  end

  after :each do
    FelFlame::Entities.each(&:delete)
    @component_manager.each(&:delete)
    @scene1.clear
    @scene2.clear
    @scene3.clear
    FelFlame::Stage.clear
  end

  it 'can add Scenes' do
    FelFlame::Stage.add @scene2, @scene1, @scene3
    expect(FelFlame::Stage.scenes).to eq([@scene2, @scene1, @scene3])
    expect(FelFlame::Stage.systems).to eq([@system1, @system2, @system3])
  end

  it 'can remove Scenes' do
    FelFlame::Stage.add @scene1, @scene2, @scene3
    FelFlame::Stage.remove @scene1, @scene3
    expect(FelFlame::Stage.scenes).to eq([@scene2])
    expect(FelFlame::Stage.systems).to eq([@system2])
  end

  it 'can clear Scenes' do
    FelFlame::Stage.add @scene1, @scene2, @scene3
    FelFlame::Stage.clear
    expect(FelFlame::Stage.scenes).to eq([])
    expect(FelFlame::Stage.systems).to eq([])
  end

  it 'can execute Systems in the correct order' do
    FelFlame::Stage.add @scene2, @scene1, @scene3
    FelFlame::Stage.call
    expect(@cmp.order).to eq([1, 2, 3])
  end

  it 'can add Systems to Scenes already added in Stage' do
    FelFlame::Stage.add @scene2, @scene1, @scene3
    system2p5 = FelFlame::Systems.new('StageAddingTest', priority: 75) do
      @component_manager.each do |component|
        component.order.push 2.5
      end
    end
    @scene2.add system2p5
    @scene3.add system2p5
    FelFlame::Stage.call
    expect(@cmp.order).to eq([1,2,2.5,3])
  end

  it 'can remove Systems to Scenes already added in Stage' do
    FelFlame::Stage.add @scene2, @scene1, @scene3
    system2p5 = FelFlame::Systems.new('StageAddingTest', priority: 75) do
      @component_manager.each do |component|
        component.order.push 2.5
      end
    end
    @scene2.add system2p5
    @scene3.add system2p5
    @scene2.remove @system2
    FelFlame::Stage.call
    expect(@cmp.order).to eq([1,2.5,3])
  end

  it 'can have Systems change priority in an existing Stage' do
    FelFlame::Stage.add @scene2, @scene1, @scene3
    @system2.priority = 0
    FelFlame::Stage.call
    expect(@cmp.order).to eq([2,1,3])
  end
end