summaryrefslogtreecommitdiffhomepage
path: root/spec/stage_manager_spec.rb
blob: 928f4c156194813cc00cef36b87455daaa7c1109 (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
# frozen_string_literal: true

require_relative '../lib/felecs'

# class EntitiesTest < Minitest::Test

describe 'Stage' do
  before :all do
    @component_manager ||= FelECS::Components.new('TestStage', order: [])
    @system2 = FelECS::Systems.new('StageTest', priority: 1) do
      @component_manager.first.order.push 2
    end
    @system1 = FelECS::Systems.new('StageMana', priority: 3) do
      @component_manager.first.order.push 1
    end
    @system3 = FelECS::Systems.new('StageSpell', priority: 2) do
      @scene1.add @system1
      @scene2.add @system2
      @scene3.add @system3
      @component_manager.first.order.push 3
    end
    @scene1 = FelECS::Scenes.new('TestStage1', priority: 1)
    @scene2 = FelECS::Scenes.new('TestStage2', priority: 2)
    @scene3 = FelECS::Scenes.new('TestStage3', priority: 3)
  end

  before :each do
    @cmp = @component_manager.new
  end

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

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

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

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

  it 'can call Scenes in correct order' do
    FelECS::Stage.add @scene2, @scene1, @scene3
    @scene1.add @system1
    @scene2.add @system2
    @scene3.add @system3
    FelECS::Stage.call
    expect(@component_manager.first.order).to eq([1, 2, 3])
  end
end