Skip to content

Commit

Permalink
Added the Defold library project
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochili committed Jun 23, 2020
1 parent 56acf2d commit 969d180
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The separated [roadmap](ROADMAP.md) contains lists with plans, known limitations

### Defold

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.
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.

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

Expand Down
19 changes: 19 additions & 0 deletions example-defold/book.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- I looked at Monsieur Fogg
* ... and I could contain myself no longer.
'What is the purpose of our journey, Monsieur?'
'A wager,' he replied.
* * 'A wager!'[] I returned.
He nodded.
* * * 'But surely that is foolishness!'
* * * 'A most serious matter then!'
- - - He nodded again.
* * * 'But can we win?'
'That is what we will endeavour to find out,' he answered.
* * * 'A modest wager, I trust?'
'Twenty thousand pounds,' he replied, quite flatly.
* * * I asked nothing further of him then[.], and after a final, polite cough, he offered nothing more to me. <>
* * 'Ah[.'],' I replied, uncertain what I thought.
- - After that, <>
* ... but I said nothing[] and <>
- we passed the day in silence.
- -> END
37 changes: 37 additions & 0 deletions example-defold/examlpe.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "main"
scale_along_z: 0
embedded_instances {
id: "example"
data: "components {\n"
" id: \"example\"\n"
" component: \"/example-defold/example.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
50 changes: 50 additions & 0 deletions example-defold/example.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
local narrator = require('narrator.narrator')

function init(self)
-- Parse and save a book.
local book = narrator.parseFile('example-defold.book', { save = true })

-- Or parse a book from the string with Ink content
-- local book = narrator.parseBook('Hello world!')

-- Or load a book from the saved lua module
-- local book = require('example-defold.book')

-- Init a story
local story = narrator.initStory(book)

-- Begin the story
story:begin()

print('--- Game started ---')

while story:canContinue() do
-- Get current paragraphs to output
local paragraphs = story:continue()

-- Output text to the player
for _, paragraph in ipairs(paragraphs) do
print(paragraph.text)
end

-- If there is no choice, it seems the game is over
if not story:canChoose() then
break
end
print('')

-- Get available choices and output them to the player
local choices = story:getChoices()
for i, choice in ipairs(choices) do
print(i .. ') ' .. choice)
end

-- Send an answer to the story to generate new paragraphs
local answer = 1
story:choose(answer)

print('')
end

print('--- Game over ---')
end
24 changes: 24 additions & 0 deletions game.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[bootstrap]
main_collection = /example-defold/examlpe.collectionc
render = /builtins/render/default.renderc

[script]
shared_state = 1

[display]
width = 960
height = 640

[android]
input_method = HiddenInputField

[project]
title = Narrator
dependencies = https://github.com/astrochili/defold-lpeg/archive/1.0.zip

[library]
include_dirs = narrator

[input]
game_binding = /builtins/input/all.input_bindingc

0 comments on commit 969d180

Please sign in to comment.