Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarEffectSourceDatabase.hpp
blob: 3ed6b92f3771881235c13efce113531832860db7 (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
#pragma once

#include "StarVector.hpp"
#include "StarJson.hpp"
#include "StarThread.hpp"
#include "StarParticle.hpp"

namespace Star {

STAR_CLASS(AudioInstance);
STAR_CLASS(EffectSource);
STAR_CLASS(EffectSourceConfig);
STAR_CLASS(EffectSourceDatabase);

class EffectSource {
public:
  EffectSource(String const& kind, String suggestedSpawnLocation, Json const& definition);
  String const& kind() const;
  void tick(float dt);
  bool expired() const;
  void stop();
  List<String> particles();
  List<AudioInstancePtr> sounds(Vec2F offset);
  void postRender();
  String effectSpawnLocation() const;
  String suggestedSpawnLocation() const;

private:
  String m_kind;
  Json m_config;
  bool m_loops;
  float m_loopDuration;
  float m_durationVariance;
  String m_effectSpawnLocation;
  String m_suggestedSpawnLocation;

  bool m_initialTick;
  bool m_loopTick;
  bool m_finalTick;
  float m_timer;
  bool m_expired;
  bool m_stop;

  List<AudioInstancePtr> m_mainSounds;
};

class EffectSourceConfig {
public:
  EffectSourceConfig(Json const& config);
  String const& kind();
  EffectSourcePtr instance(String const& suggestedSpawnLocation);

private:
  String m_kind;
  Json m_config;
};

class EffectSourceDatabase {
public:
  EffectSourceDatabase();

  EffectSourceConfigPtr effectSourceConfig(String const& kind) const;

private:
  StringMap<EffectSourceConfigPtr> m_sourceConfigs;
};

List<Particle> particlesFromDefinition(Json const& config, Vec2F const& position = Vec2F());
List<AudioInstancePtr> soundsFromDefinition(Json const& config, Vec2F const& position = Vec2F());

}