View Source DevJoy.Scene behaviour (DevJoy v1.1.0)
Scene defines DSL which stores scene parts within get_part/0
and get_part/1
function.
Examples
In order to use the DevJoy
DSL simply add use DevJoy.Scene
at the top of your module
defmodule MyApp.SceneName do
use DevJoy.Scene
# parts DSL goes here
end
The optional translation is done at runtime, so you can use it as same as any other module. To enable runtime translation all you need to do is to pass your gettext module as shown below.
defmodule MyApp.Gettext do
use Gettext, otp_app: :my_app
end
defmodule MyApp.SceneWithGettext do
use DevJoy.Scene, gettext_module: MyApp.Gettext
# parts DSL goes here
end
Summary
Functions
A DSL for DevJoy.Scene.Asset
struct
A DSL for DevJoy.Scene.Challenge
struct
A DSL for DevJoy.Scene.Chapter
struct
A DSL for DevJoy.Scene.Choice
struct
Returns a quoted anonymous function to place it within get_part/1
function.
Once called, function fetches character and passes it along with choices
to the function defined in second argument.
The function in 2nd argument should call an action for one of passed choices.
This allows to follow a choice based on a runtime condition.
A DSL for DevJoy.Scene.Dialog
struct
The same as goto/2
, but defaults to current scene.
Returns a quoted anonymous function to place it within get_part/1
function.
Once called, function returns a data of specified part.
This allows to easily navigate to other part or even scene.
A DSL for DevJoy.Scene.Menu
struct
A DSL for DevJoy.Scene.Part
struct
A DSL for DevJoy.Scene.Dialog
struct with support for choices
Types
Callbacks
@callback get_part() :: DevJoy.Scene.Part.t()
Returns a main part of scene
@callback get_part(DevJoy.Scene.Part.name()) :: DevJoy.Scene.Part.t()
Returns a part of scene
Functions
@spec asset(DevJoy.Scene.Asset.path(), DevJoy.Scene.Asset.data()) :: Macro.output()
A DSL for DevJoy.Scene.Asset
struct
@spec challenge(DevJoy.Scene.Challenge.type(), DevJoy.Scene.Challenge.data()) :: Macro.output()
A DSL for DevJoy.Scene.Challenge
struct
@spec chapter( DevJoy.Scene.Chapter.index(), DevJoy.Scene.Chapter.title(), DevJoy.Scene.Chapter.description() ) :: Macro.output()
A DSL for DevJoy.Scene.Chapter
struct
@spec choice(DevJoy.Scene.Choice.content(), Macro.input()) :: Macro.output()
A DSL for DevJoy.Scene.Choice
struct
@spec condition( DevJoy.Character.id(), (DevJoy.Character.t(), [DevJoy.Scene.Choice.t(atom())] -> term()), [{:do, Macro.input()}] ) :: Macro.output()
Returns a quoted anonymous function to place it within get_part/1
function.
Once called, function fetches character and passes it along with choices
to the function defined in second argument.
The function in 2nd argument should call an action for one of passed choices.
This allows to follow a choice based on a runtime condition.
Unlike in menu/2
or question/4
the choices are not supposed to be displayed as buttons
and therefore their content could be an atom and so since it does not need to be translated
it should simplify the condition in passed function.
Example
defmodule MyApp do
def some_func(_character, choices) do
Enum.random(choices).action()
end
end
defmodule MyApp.SceneWithCondition do
use DevJoy.Scene
part :condition do
condition :john_doe, &MyApp.some_func/2 do
choice :choiceA, goto(:partA)
choice :choiceB, goto(:partB)
end
end
part :partA do
# elements for part A goes here
end
part :partB do
# elements for part B goes here
end
end
@spec dialog( DevJoy.Character.id(), DevJoy.Scene.Dialog.side(), DevJoy.Scene.Dialog.content() ) :: Macro.output()
A DSL for DevJoy.Scene.Dialog
struct
@spec goto() :: Macro.output()
The same as goto/2
, but defaults to current scene and :main
part.
@spec goto(DevJoy.Scene.Part.name()) :: Macro.output()
The same as goto/2
, but defaults to current scene.
@spec goto(DevJoy.Scene.Part.scene(), DevJoy.Scene.Part.name()) :: Macro.output()
Returns a quoted anonymous function to place it within get_part/1
function.
Once called, function returns a data of specified part.
This allows to easily navigate to other part or even scene.
Example
defmodule MyApp.SceneName do
use DevJoy.Scene
part :partA do
goto(:partB)
end
part :partB do
goto(MyApp.AnotherSceneName, :partA)
end
end
@spec part(DevJoy.Scene.Part.name(), DevJoy.Scene.Part.page_title(), [ {:do, Macro.input()} ]) :: Macro.output()
A DSL for DevJoy.Scene.Part
struct
@spec question( DevJoy.Character.id(), DevJoy.Scene.Dialog.side(), DevJoy.Scene.Dialog.content(), [ {:do, Macro.input()} ] ) :: Macro.output()
A DSL for DevJoy.Scene.Dialog
struct with support for choices
Example
defmodule MyApp.SceneWithQuestion do
use DevJoy.Scene
part :question do
question :john_doe, "Example question" do
choice "Example answer", goto(:part_name)
end
end
end