aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lkn/core.ex
blob: 0033ecd127d2cb122e705604c3888ca501aed15b (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
#
# lkn.core: an entity-component-system (ecs) implementation for lyxan
# Copyright (C) 2017 Thomas Letan <contact@thomasletan.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
defmodule Lkn.Core do
  defmodule Name do
    @moduledoc false

    @type t :: term

    alias Lkn.Core.Entity
    alias Lkn.Core.Map
    alias Lkn.Core.Entity
    alias Lkn.Core.Instance
    alias Lkn.Core.System

    @spec properties(Entity.k) :: t
    def properties(entity_key) do
      {:via, Registry, {Lkn.Core.Registry, {:entity, entity_key, :props}}}
    end

    @spec component(Entity.k, System.m) :: t
    def component(entity_key, system) do
      {:via, Registry, {Lkn.Core.Registry, {:entity, entity_key, system}}}
    end

    @spec comps_list(Entity.k) :: t
    def comps_list(entity_key) do
      {:via, Registry, {Lkn.Core.Registry, {:entity, entity_key, :comps_list}}}
    end

    @spec entity(Entity.k) :: t
    def entity(entity_key) do
      {:via, Registry, {Lkn.Core.Registry, {:entity, entity_key}}}
    end

    @spec system(Instance.k, System.m) :: t
    def system(instance_key, sys) do
      {:via, Registry, {Lkn.Core.Registry, {:engine, instance_key, sys}}}
    end

    @spec instance(Instance.k) :: t
    def instance(instance_key) do
      {:via, Registry, {Lkn.Core.Registry, {:instance, instance_key}}}
    end

    @spec puppeteer(Puppeteer.k) :: t
    def puppeteer(puppeteer_key) do
      {:via, Registry, {Lkn.Core.Registry, {:puppeteer, puppeteer_key}}}
    end

    @spec pool(Map.k) :: t
    def pool(map_key) do
      {:via, Registry, {Lkn.Core.Registry, {:pool, map_key}}}
    end

    @spec instance_sup(Map.k) :: t
    def instance_sup(map_key) do
      {:via, Registry, {Lkn.Core.Registry, {:pool, map_key, :sup}}}
    end
  end

  use Application

  import Supervisor.Spec

  @doc false
  def start(_type, _args) do
    Supervisor.start_link(__MODULE__, :ok)
  end

  @doc false
  @spec init(any) ::
  {:ok, {:supervisor.sup_flags, [Supervisor.Spec.spec]}} |
  :ignore
  def init(_) do
    children = [
      supervisor(Registry, [:unique, Lkn.Core.Registry], id: :core_registry),
      supervisor(Lkn.Core.Pool.Supervisor, [])
    ]

    supervise(children, strategy: :one_for_all)
  end
end