From 969d180408d46dc5f3b1567a15f79e48bcbe8aa3 Mon Sep 17 00:00:00 2001 From: Roman Silin Date: Tue, 23 Jun 2020 21:24:58 +0300 Subject: [PATCH] Added the Defold library project --- README.md | 2 +- example-defold/book.ink | 19 ++++++++++++ example-defold/examlpe.collection | 37 +++++++++++++++++++++++ example-defold/example.script | 50 +++++++++++++++++++++++++++++++ game.project | 24 +++++++++++++++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 example-defold/book.ink create mode 100644 example-defold/examlpe.collection create mode 100644 example-defold/example.script create mode 100644 game.project diff --git a/README.md b/README.md index 30ae81d..83fc469 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/example-defold/book.ink b/example-defold/book.ink new file mode 100644 index 0000000..d6317a2 --- /dev/null +++ b/example-defold/book.ink @@ -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 \ No newline at end of file diff --git a/example-defold/examlpe.collection b/example-defold/examlpe.collection new file mode 100644 index 0000000..d405a3d --- /dev/null +++ b/example-defold/examlpe.collection @@ -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 + } +} diff --git a/example-defold/example.script b/example-defold/example.script new file mode 100644 index 0000000..3b0ea5f --- /dev/null +++ b/example-defold/example.script @@ -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 \ No newline at end of file diff --git a/game.project b/game.project new file mode 100644 index 0000000..99f6c9f --- /dev/null +++ b/game.project @@ -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 +