Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%{
configs: [
%{
name: "default",
strict: true,
files: %{included: ["lib/", "apps/"], excluded: []},
checks: [
{Credo.Check.Refactor.Nesting, [max_nesting: 4]},
{Credo.Check.Refactor.CyclomaticComplexity, [max_complexity: 10]},
{Credo.Check.Design.AliasUsage, false},
{Credo.Check.Design.TagTODO, false}
]
}
]
}
File renamed without changes.
4 changes: 3 additions & 1 deletion apps/contents/lib/components/category/physics_entity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ defmodule Contents.Components.Category.PhysicsEntity do
inj
else
runner = content.flow_runner(Map.get(context, :room_id, :main))
playing_state = (runner && Contents.Scenes.Stack.get_scene_state(runner, content.playing_scene())) || %{}

playing_state =
(runner && Contents.Scenes.Stack.get_scene_state(runner, content.playing_scene())) || %{}

player_hp = Map.get(playing_state, :player_hp, 100.0)
invincible_until_ms = Map.get(playing_state, :invincible_until_ms)
Expand Down
5 changes: 3 additions & 2 deletions apps/contents/lib/components/category/spawner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ defmodule Contents.Components.Category.Spawner do

if function_exported?(content, :entity_params_for_nif, 0) do
case content.entity_params_for_nif() do
{enemies, weapons, bosses} when is_list(enemies) and is_list(weapons) and is_list(bosses) ->
{enemies, weapons, bosses}
when is_list(enemies) and is_list(weapons) and is_list(bosses) ->
Core.NifBridge.set_entity_params(world_ref, enemies, weapons, bosses, nil)

other ->
raise ArgumentError,
"entity_params_for_nif/0 must return {enemies, weapons, bosses}, got: #{inspect(other)}"
"entity_params_for_nif/0 must return {enemies, weapons, bosses}, got: #{inspect(other)}"
end
end

Expand Down
21 changes: 0 additions & 21 deletions apps/contents/lib/contents/asteroid_arena.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,10 @@ defmodule Content.AsteroidArena do

defp map_transition_module_to_scene_type({:continue, state}), do: {:continue, state}

defp map_transition_module_to_scene_type({:continue, state, opts}),
do: {:continue, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, :pop, state}),
do: {:transition, :pop, state}

defp map_transition_module_to_scene_type({:transition, :pop, state, opts}),
do: {:transition, :pop, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state, opts}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state, opts}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp scene_module_to_type(Content.AsteroidArena.Playing), do: :playing
defp scene_module_to_type(Content.AsteroidArena.GameOver), do: :game_over
defp scene_module_to_type(mod), do: raise("unknown scene module: #{inspect(mod)}")
Expand Down
21 changes: 0 additions & 21 deletions apps/contents/lib/contents/bullet_hell_3d.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,10 @@ defmodule Content.BulletHell3D do
@doc false
defp map_transition_module_to_scene_type({:continue, state}), do: {:continue, state}

defp map_transition_module_to_scene_type({:continue, state, opts}),
do: {:continue, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, :pop, state}),
do: {:transition, :pop, state}

defp map_transition_module_to_scene_type({:transition, :pop, state, opts}),
do: {:transition, :pop, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state, opts}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state, opts}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp scene_module_to_type(Content.BulletHell3D.Playing), do: :playing
defp scene_module_to_type(Content.BulletHell3D.GameOver), do: :game_over
defp scene_module_to_type(mod), do: raise("unknown scene module: #{inspect(mod)}")
Expand Down
15 changes: 12 additions & 3 deletions apps/contents/lib/contents/bullet_hell_3d/playing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ defmodule Content.BulletHell3D.Playing do
@impl Contents.SceneBehaviour
def update(_context, state) do
if state.hp <= 0 do
{:transition,
{:replace, Content.BulletHell3D.GameOver, %{elapsed_sec: state.elapsed_sec}}, state}
{:transition, {:replace, Content.BulletHell3D.GameOver, %{elapsed_sec: state.elapsed_sec}},
state}
else
new_state = tick(state)
{:continue, new_state}
Expand Down Expand Up @@ -172,6 +172,7 @@ defmodule Content.BulletHell3D.Playing do
end

{px, py, pz} = player

player_cmd =
{:box_3d, px, py + @player_half, pz, @player_half, @player_half,
{@player_half, pr, pg, pb, alpha}}
Expand Down Expand Up @@ -486,7 +487,14 @@ defmodule Content.BulletHell3D.Playing do

# ── 発射タイマー ──────────────────────────────────────────────────

defp update_shoot_timer(bullet_objects, timer_ms, next_id, enemy_objects, player_pos, shoot_interval_ms) do
defp update_shoot_timer(
bullet_objects,
timer_ms,
next_id,
enemy_objects,
player_pos,
shoot_interval_ms
) do
new_timer = timer_ms - trunc(@tick_ms)

if new_timer <= 0 and enemy_objects != [] do
Expand All @@ -507,6 +515,7 @@ defmodule Content.BulletHell3D.Playing do
if len > 0.001 do
vx = ddx / len * @bullet_speed
vz = ddz / len * @bullet_speed

bullet_obj =
ObjectStruct.new(
name: "Bullet_#{id}",
Expand Down
15 changes: 5 additions & 10 deletions apps/contents/lib/contents/canvas_test/playing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ defmodule Content.CanvasTest.Playing do
"""
@behaviour Contents.SceneBehaviour

alias Contents.Objects.Core.Struct, as: ObjectStruct
alias Contents.Components.Category.Procedural.Meshes.Box
alias Contents.Components.Category.Shader.Skybox
alias Contents.Objects.Core.CreateEmptyChild
alias Contents.Objects.Core.Struct, as: ObjectStruct
alias Structs.Category.Space.Transform
alias Contents.Components.Category.Shader.Skybox
alias Contents.Components.Category.Procedural.Meshes.Box

@tick_sec 1.0 / 60.0

Expand Down Expand Up @@ -118,13 +118,8 @@ defmodule Content.CanvasTest.Playing do

# init/1 では起動時エラーを即失敗させたいため raise。上位で {:error, reason} を扱う構成にすることも可。
for panel_def <- panel_definitions do
case CreateEmptyChild.create(top_object, name: panel_def.name) do
{:ok, child} ->
%{child | transform: %Transform{position: panel_def.position}}

{:error, reason} ->
raise "CanvasTest.Playing init: CreateEmptyChild.create failed for '#{panel_def.name}': #{inspect(reason)}"
end
{:ok, child} = CreateEmptyChild.create(top_object, name: panel_def.name)
%{child | transform: %Transform{position: panel_def.position}}
end
end

Expand Down
14 changes: 4 additions & 10 deletions apps/contents/lib/contents/formula_test/playing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ defmodule Content.FormulaTest.Playing do
@behaviour Contents.SceneBehaviour

alias Structs.Category.Space.Transform
alias Structs.Category.Value.Float, as: ValueFloat
alias Structs.Category.Value.Color, as: Color
alias Structs.Category.Value.Float, as: ValueFloat

# Contents.Nodes.Test.Formula.run/0 の戻り型と合わせて String.t() を使用
@type formula_result :: {:ok, String.t(), term()} | {:error, String.t(), term()}
Expand Down Expand Up @@ -95,9 +95,9 @@ defmodule Content.FormulaTest.Playing do
}
end

alias Contents.Objects.Core.Struct, as: ObjectStruct
alias Contents.Objects.Core.CreateEmptyChild
alias Contents.Components.Category.Shader.Skybox
alias Contents.Objects.Core.CreateEmptyChild
alias Contents.Objects.Core.Struct, as: ObjectStruct

@impl Contents.SceneBehaviour
@spec init(term()) :: {:ok, state()}
Expand All @@ -111,13 +111,7 @@ defmodule Content.FormulaTest.Playing do
# Scene 直下のトップレベルは User のみ。Child は User の子なので children には含めない。
# 作成した Child を本シーンで参照する必要はないため、戻り値は束縛しない。
# init/1 では起動時エラーを即失敗させたいため raise。上位で {:error, reason} を扱う構成にすることも可。
case CreateEmptyChild.create(top_object, name: "Child") do
{:ok, _child} ->
:ok

{:error, reason} ->
raise "FormulaTest.Playing init: CreateEmptyChild.create failed for 'Child': #{inspect(reason)}"
end
{:ok, _child} = CreateEmptyChild.create(top_object, name: "Child")

state = %{
origin: origin,
Expand Down
2 changes: 2 additions & 0 deletions apps/contents/lib/contents/frame_encoder.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Content.FrameEncoder do
require Logger

@moduledoc """
Zenoh フレーム配信用 Erlang term バイナリエンコーダ。

Expand Down
21 changes: 0 additions & 21 deletions apps/contents/lib/contents/rolling_ball.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,10 @@ defmodule Content.RollingBall do

defp map_transition_module_to_scene_type({:continue, state}), do: {:continue, state}

defp map_transition_module_to_scene_type({:continue, state, opts}),
do: {:continue, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, :pop, state}),
do: {:transition, :pop, state}

defp map_transition_module_to_scene_type({:transition, :pop, state, opts}),
do: {:transition, :pop, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state, opts}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state, opts}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp scene_module_to_type(Content.RollingBall.Title), do: :title
defp scene_module_to_type(Content.RollingBall.Playing), do: :playing
defp scene_module_to_type(Content.RollingBall.StageClear), do: :stage_clear
Expand Down
32 changes: 26 additions & 6 deletions apps/contents/lib/contents/rolling_ball/playing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,24 @@ defmodule Content.RollingBall.Playing do
tile_size: @tile_size,
ball_start: {-8.0, -8.0},
goal_pos: {8.0, 8.0},
holes:
[{1, 1}, {5, 1}, {8, 1}, {1, 5}, {8, 5}, {1, 8}, {5, 8}, {8, 8}, {3, 3}, {6, 3}, {3, 6},
{6, 6}, {4, 0}, {0, 4}, {9, 4}, {4, 9}],
holes: [
{1, 1},
{5, 1},
{8, 1},
{1, 5},
{8, 5},
{1, 8},
{5, 8},
{8, 8},
{3, 3},
{6, 3},
{3, 6},
{6, 6},
{4, 0},
{0, 4},
{9, 4},
{4, 9}
],
obstacles: [{4.0, 0.0}, {-4.0, 0.0}, {0.0, 4.0}, {0.0, -4.0}],
moving_obstacles: [
%{id: 0, x: 2.0, z: 2.0, vx: 3.0, vz: 0.0, range: 4.0},
Expand Down Expand Up @@ -406,9 +421,12 @@ defmodule Content.RollingBall.Playing do

defp build_goal_cmds(scene_state) do
case Map.get(scene_state, :goal_pos) do
nil -> []
nil ->
[]

{gx, gz} ->
{gr, gg, gb, ga} = @color_goal

[
{:box_3d, gx, @goal_half_y, gz, @goal_half_xz, @goal_half_y,
{@goal_half_xz, gr, gg, gb, ga}}
Expand Down Expand Up @@ -495,7 +513,8 @@ defmodule Content.RollingBall.Playing do
{:node, {:top_left, {0.0, 0.0}, :wrap},
{:text, "WASD / Arrow Keys: Move", {0.59, 0.67, 0.75, 1.0}, 13.0, false}, []},
{:node, {:top_left, {0.0, 0.0}, :wrap},
{:text, "Reach the green goal to clear the stage", {0.59, 0.67, 0.75, 1.0}, 13.0, false}, []},
{:text, "Reach the green goal to clear the stage", {0.59, 0.67, 0.75, 1.0}, 13.0, false},
[]},
{:node, {:top_left, {0.0, 0.0}, :wrap},
{:button, " START GAME ", "__start__", {0.16, 0.39, 0.78, 1.0}, 200.0, 50.0}, []}
]
Expand Down Expand Up @@ -533,7 +552,8 @@ defmodule Content.RollingBall.Playing do
{:node, {:top_left, {0.0, 0.0}, :wrap},
{:text, "All stages cleared!", {0.86, 0.78, 0.59, 1.0}, 18.0, false}, []},
{:node, {:top_left, {0.0, 0.0}, :wrap},
{:button, " BACK TO TITLE ", "__back_to_title__", {0.47, 0.31, 0.08, 1.0}, 200.0, 50.0}, []}
{:button, " BACK TO TITLE ", "__back_to_title__", {0.47, 0.31, 0.08, 1.0}, 200.0, 50.0},
[]}
]

{:node, {:center, {0.0, 0.0}, :wrap},
Expand Down
21 changes: 0 additions & 21 deletions apps/contents/lib/contents/simple_box_3d.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,10 @@ defmodule Content.SimpleBox3D do

defp map_transition_module_to_scene_type({:continue, state}), do: {:continue, state}

defp map_transition_module_to_scene_type({:continue, state, opts}),
do: {:continue, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, :pop, state}),
do: {:transition, :pop, state}

defp map_transition_module_to_scene_type({:transition, :pop, state, opts}),
do: {:transition, :pop, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state, opts}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state, opts}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp scene_module_to_type(Content.SimpleBox3D.Scenes.Playing), do: :playing
defp scene_module_to_type(Content.SimpleBox3D.Scenes.GameOver), do: :game_over
defp scene_module_to_type(mod), do: raise("unknown scene module: #{inspect(mod)}")
Expand Down
17 changes: 0 additions & 17 deletions apps/contents/lib/contents/vampire_survivor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,14 @@ defmodule Content.VampireSurvivor do

defp map_transition_module_to_scene_type({:continue, state}), do: {:continue, state}

defp map_transition_module_to_scene_type({:continue, state, opts}),
do: {:continue, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, :pop, state}),
do: {:transition, :pop, state}

defp map_transition_module_to_scene_type({:transition, :pop, state, opts}),
do: {:transition, :pop, state, opts || %{}}

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:push, mod, arg}, state, opts}) do
{:transition, {:push, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state}
end

defp map_transition_module_to_scene_type({:transition, {:replace, mod, arg}, state, opts}) do
{:transition, {:replace, scene_module_to_type(mod), arg}, state, opts || %{}}
end

defp scene_module_to_type(Content.VampireSurvivor.Playing), do: :playing
defp scene_module_to_type(Content.VampireSurvivor.GameOver), do: :game_over
defp scene_module_to_type(Content.VampireSurvivor.LevelUp), do: :level_up
Expand Down
5 changes: 2 additions & 3 deletions apps/contents/lib/contents/vampire_survivor/frame_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ defmodule Content.VampireSurvivor.FrameBuilder do
def build(playing_state, context) do
content = Core.Config.current()

{{player_x, player_y, frame_id, enemy_count, bullet_count},
{magnet_timer, invincible_timer}, {enemies, bullets, particles},
{items, obstacles, _boss_nif, score_popups}} =
{{player_x, player_y, frame_id, enemy_count, bullet_count}, {magnet_timer, invincible_timer},
{enemies, bullets, particles}, {items, obstacles, _boss_nif, score_popups}} =
Core.NifBridge.get_render_entities(context.world_ref)

anim_frame = rem(div(frame_id, 4), 4)
Expand Down
Loading
Loading