Skip to content

Commit 969d180

Browse files
committed
Added the Defold library project
1 parent 56acf2d commit 969d180

5 files changed

Lines changed: 131 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The separated [roadmap](ROADMAP.md) contains lists with plans, known limitations
8282

8383
### Defold
8484

85-
Add the link to the latest [zip-archive for Defold](https://github.com/astrochili/narrator/releases) as a [library dependency](http://www.defold.com/manuals/libraries/) in the Defold project configuration. Then you can require it as described in the [Common case](#common-case) section.
85+
Add the link to the latest [release zip-archive](https://github.com/astrochili/narrator/releases) as a [library dependency](http://www.defold.com/manuals/libraries/) in the Defold project configuration. Then you can require it as described in the [Common case](#common-case) section.
8686

8787
Narrator aready has [defold-lpeg](https://github.com/astrochili/defold-lpeg) as a library dependency.
8888

example-defold/book.ink

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- I looked at Monsieur Fogg
2+
* ... and I could contain myself no longer.
3+
'What is the purpose of our journey, Monsieur?'
4+
'A wager,' he replied.
5+
* * 'A wager!'[] I returned.
6+
He nodded.
7+
* * * 'But surely that is foolishness!'
8+
* * * 'A most serious matter then!'
9+
- - - He nodded again.
10+
* * * 'But can we win?'
11+
'That is what we will endeavour to find out,' he answered.
12+
* * * 'A modest wager, I trust?'
13+
'Twenty thousand pounds,' he replied, quite flatly.
14+
* * * I asked nothing further of him then[.], and after a final, polite cough, he offered nothing more to me. <>
15+
* * 'Ah[.'],' I replied, uncertain what I thought.
16+
- - After that, <>
17+
* ... but I said nothing[] and <>
18+
- we passed the day in silence.
19+
- -> END

example-defold/examlpe.collection

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "main"
2+
scale_along_z: 0
3+
embedded_instances {
4+
id: "example"
5+
data: "components {\n"
6+
" id: \"example\"\n"
7+
" component: \"/example-defold/example.script\"\n"
8+
" position {\n"
9+
" x: 0.0\n"
10+
" y: 0.0\n"
11+
" z: 0.0\n"
12+
" }\n"
13+
" rotation {\n"
14+
" x: 0.0\n"
15+
" y: 0.0\n"
16+
" z: 0.0\n"
17+
" w: 1.0\n"
18+
" }\n"
19+
"}\n"
20+
""
21+
position {
22+
x: 0.0
23+
y: 0.0
24+
z: 0.0
25+
}
26+
rotation {
27+
x: 0.0
28+
y: 0.0
29+
z: 0.0
30+
w: 1.0
31+
}
32+
scale3 {
33+
x: 1.0
34+
y: 1.0
35+
z: 1.0
36+
}
37+
}

example-defold/example.script

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
local narrator = require('narrator.narrator')
2+
3+
function init(self)
4+
-- Parse and save a book.
5+
local book = narrator.parseFile('example-defold.book', { save = true })
6+
7+
-- Or parse a book from the string with Ink content
8+
-- local book = narrator.parseBook('Hello world!')
9+
10+
-- Or load a book from the saved lua module
11+
-- local book = require('example-defold.book')
12+
13+
-- Init a story
14+
local story = narrator.initStory(book)
15+
16+
-- Begin the story
17+
story:begin()
18+
19+
print('--- Game started ---')
20+
21+
while story:canContinue() do
22+
-- Get current paragraphs to output
23+
local paragraphs = story:continue()
24+
25+
-- Output text to the player
26+
for _, paragraph in ipairs(paragraphs) do
27+
print(paragraph.text)
28+
end
29+
30+
-- If there is no choice, it seems the game is over
31+
if not story:canChoose() then
32+
break
33+
end
34+
print('')
35+
36+
-- Get available choices and output them to the player
37+
local choices = story:getChoices()
38+
for i, choice in ipairs(choices) do
39+
print(i .. ') ' .. choice)
40+
end
41+
42+
-- Send an answer to the story to generate new paragraphs
43+
local answer = 1
44+
story:choose(answer)
45+
46+
print('')
47+
end
48+
49+
print('--- Game over ---')
50+
end

game.project

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[bootstrap]
2+
main_collection = /example-defold/examlpe.collectionc
3+
render = /builtins/render/default.renderc
4+
5+
[script]
6+
shared_state = 1
7+
8+
[display]
9+
width = 960
10+
height = 640
11+
12+
[android]
13+
input_method = HiddenInputField
14+
15+
[project]
16+
title = Narrator
17+
dependencies = https://github.com/astrochili/defold-lpeg/archive/1.0.zip
18+
19+
[library]
20+
include_dirs = narrator
21+
22+
[input]
23+
game_binding = /builtins/input/all.input_bindingc
24+

0 commit comments

Comments
 (0)