├── .travis.yml ├── .luacheckrc ├── main.lua ├── erogodic.lua ├── README.md ├── demo └── talkies.lua └── spec.lua /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | 4 | env: 5 | - LUA="lua=5.1" 6 | - LUA="luajit=2.0" 7 | - LUA="luajit=2.1" 8 | 9 | before_install: 10 | - pip install hererocks 11 | - hererocks lua_install -r^ --$LUA 12 | - export PATH=$PATH:$PWD/lua_install/bin 13 | 14 | install: 15 | - luarocks install busted 16 | - luarocks install luacheck 17 | - luarocks install luacov 18 | 19 | script: 20 | - busted --verbose --coverage spec.lua 21 | - luacheck . 22 | 23 | after_success: 24 | - luacov 25 | - bash <(curl -s https://codecov.io/bash) 26 | 27 | notifications: 28 | email: 29 | on_success: change 30 | on_failure: always 31 | -------------------------------------------------------------------------------- /.luacheckrc: -------------------------------------------------------------------------------- 1 | max_line_length = false 2 | allow_defined = false -- Do NOT allow implicitly defined globals. 3 | allow_defined_top = false -- Do NOT allow implicitly defined globals. 4 | 5 | globals = { 6 | 'get', 7 | 'menu', 8 | 'msg', 9 | 'name', 10 | 'option', 11 | 'selection', 12 | } 13 | 14 | files = { 15 | ['erogodic.lua'] = { 16 | std = 'luajit', 17 | }, 18 | ['main.lua'] = { 19 | std = 'luajit+love', 20 | globals = { 21 | 'giveItem', 22 | }, 23 | }, 24 | ['spec.lua'] = { 25 | std = 'luajit+busted', 26 | globals = { 27 | 'attr', 28 | 'characterName', 29 | 'effect', 30 | 'font', 31 | 'image', 32 | 'kaban', 33 | 'myMacro', 34 | 'mySubmacro', 35 | 'serval', 36 | 'undefinedGlobal', 37 | 'wifeName', 38 | }, 39 | }, 40 | } 41 | 42 | exclude_files = { 43 | 'lua_install/*', -- CI: hererocks 44 | 'demo/*', 45 | } -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | local Ero = require 'erogodic' 2 | local script = Ero(function() 3 | name "Shopkeeper" 4 | msg "Thank you for rescuing my beloved tomboyish daughter!" 5 | local baklava = option "Delicious Baklava" 6 | local hamster = option "Loyal Hamster" 7 | menu "Select your reward" 8 | if selection(baklava) then 9 | giveItem("Baklava") 10 | elseif selection(hamster) then 11 | giveItem("Hamster") 12 | end 13 | msg "Also, take this powerful weapon!" 14 | giveItem("Slightly-Rusted Dwarfbane +3") 15 | msg "Farewell!" 16 | end) 17 | :defineAttributes({ 18 | 'name', 19 | }) 20 | :addMacro('giveItem', function(item) 21 | local lastName = get('name') 22 | name "" 23 | msg("You got the " .. item .. "!") 24 | name(lastName) 25 | end) 26 | 27 | local Talkies = require 'demo.talkies' 28 | Talkies.backgroundColor = {1, 1, 1, 0.2} 29 | Talkies.textSpeed = 'medium' 30 | Talkies.font = love.graphics.newFont(24) 31 | 32 | local displayMessageNode 33 | 34 | local function nextMessage() 35 | local node = script:next() 36 | displayMessageNode(node) 37 | end 38 | 39 | local function selectOption(selection) 40 | local node = script:select(selection) 41 | displayMessageNode(node) 42 | end 43 | 44 | displayMessageNode = function(node) 45 | if node == nil then 46 | return -- Erogodic script is over. 47 | end 48 | 49 | local config = {} 50 | if node.options then 51 | config.options = {} 52 | for i, opt in ipairs(node.options) do 53 | local onSelect = function() 54 | selectOption(opt) 55 | end 56 | config.options[i] = {opt, onSelect} 57 | end 58 | else 59 | config.oncomplete = nextMessage 60 | end 61 | Talkies.say(node.name, node.msg, config) 62 | end 63 | 64 | function love.load() 65 | nextMessage() 66 | end 67 | 68 | function love.update(dt) 69 | Talkies.update(dt) 70 | end 71 | 72 | function love.keypressed(key) 73 | if key == 'space' or key == 'return' or key == 'e' or key == 'z' then 74 | Talkies.onAction() 75 | elseif key == 'up' or key == 'w' then 76 | Talkies.prevOption() 77 | elseif key == 'down' or key == 's' then 78 | Talkies.nextOption() 79 | elseif key == 'escape' then 80 | love.event.push('quit') 81 | end 82 | end 83 | 84 | function love.draw() 85 | Talkies.draw() 86 | if Talkies.isOpen() == false then 87 | love.graphics.print('