{"id":16085192,"url":"https://github.com/Megus/whdefquest","last_synced_at":"2025-10-23T01:31:45.699Z","repository":{"id":78909232,"uuid":"188274326","full_name":"Megus/whdefquest","owner":"Megus","description":"A little helper library to create quests in Defold game engine","archived":false,"fork":false,"pushed_at":"2019-05-25T19:39:48.000Z","size":306,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-13T04:30:51.425Z","etag":null,"topics":["defold","defold-game-engine"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Megus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-23T16:58:09.000Z","updated_at":"2024-12-27T11:21:53.000Z","dependencies_parsed_at":"2023-03-13T20:11:03.303Z","dependency_job_id":null,"html_url":"https://github.com/Megus/whdefquest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Megus/whdefquest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Megus%2Fwhdefquest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Megus%2Fwhdefquest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Megus%2Fwhdefquest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Megus%2Fwhdefquest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Megus","download_url":"https://codeload.github.com/Megus/whdefquest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Megus%2Fwhdefquest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280546390,"owners_count":26348719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-game-engine"],"created_at":"2024-10-09T13:01:52.231Z","updated_at":"2025-10-23T01:31:45.430Z","avatar_url":"https://github.com/Megus.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"# whDefQuest\n\nA little helper library for quest games created with Defold game engine. The basic functions it gives are:\n\n- Inventory management\n- Dialogues with NPC\n\nThe library itself doesn't use any Defold-specific API, so you can use it with any other game engine.\n\nTo add whDefQuest to your Defold project, add this link to a dependency list:\n\nhttps://github.com/Megus/whdefquest/archive/1.0.0.zip\n\n## Table of contents\n\n- [How to use](#how-to-use)\n- [whDefQuest functions](#whdefquest-functions)\n  - [```defquest.init(level, delegate)```](#defquestinitlevel-delegate)\n  - [```defquest.final()```](#defquestfinal)\n  - [```defquest.add_module(module)```](#defquestadd_modulemodule)\n  - [```defquest.act_npc(npc)```](#defquestact_npcnpc)\n- [NPC interaction helper functions](#npc-interaction-helper-functions)\n  - [```defquest.show_dialogue(dialogue)```](#defquestshow_dialoguedialogue)\n  - [```defquest.show_choice(options)```](#defquestshow_choiceoptions)\n  - [```defquest.finish_act()```](#defquestfinish_act)\n  - [```defquest.on_dialogue_done()```](#defqueston_dialogue_done)\n  - [```defquest.on_choice_selected(choice)```](#defqueston_choice_selectedchoice)\n- [Inventory module functions](#inventory-module-functions)\n  - [```defquest.inventory.pick_item(item)```](#defquestinventorypick_itemitem)\n  - [```defquest.inventory.remove_item(item)```](#defquestinventoryremove_itemitem)\n  - [```defquest.inventory.has_item(item)```](#defquestinventoryhas_itemitem)\n- [Level table](#level-table)\n  - [```init()```](#init)\n  - [```final()```](#final)\n  - [```on_pick_item(defquest, item)```](#on_pick_itemdefquest-item)\n  - [```on_act_npc(defquest, npc)```](#on_act_npcdefquest-npc)\n- [whDefQuest delegate](#whdefquest-delegate)\n  - [```on_pick_item(item)```](#on_pick_itemitem)\n  - [```on_update_inventory(items)```](#on_update_inventoryitems)\n  - [```on_inventory_full()```](#on_inventory_full)\n  - [```on_finish_act()```](#on_finish_act)\n  - [```show_dialogue(dialogue)```](#show_dialoguedialogue)\n  - [```show_choice(options)```](#show_choiceoptions)\n\n----\n\n## How to use\n\nImport ```whdefquest/defquest.lua``` and initialize the library:\n\n```lua\ndefquest.init(level, delegate)\n```\n\n```level``` is the level table. It encapsulates the level logic and can expose some functions: ```init()```, ```final()```, ```on_pick_item(defquest, item)```, ```on_act_npc(defquest, npc)```. All these functions are optional, the library will check if they exist in the level table. More details on these functions later.\n\n```delegate``` is the library delegate. Your game should react to events. The delegate can implement the following functions: ```on_pick_item(item)```, ```on_inventory_full()```, ```on_update_inventory(items)```, ```show_dialogue(dialogue)```, ```show_choice(options)```. More details in the following sections.\n\nAfter initialization you can call other whDefQuest functions, see the documentation below.\n\n----\n\n## whDefQuest functions\n\n#### ```defquest.init(level, delegate)```\n\nInitializes the library with the level and delegate tables. It also registers all built-in modules (currently it's the inventory module).\n\nYou can access level and delegate later by referencing ```defquest.level``` and ```defquest.delegate```.\n\n#### ```defquest.final()```\n\nCall this when you're done with the level. This functions frees up all resources and unregisters all modules.\n\n#### ```defquest.add_module(module)```\n\nwhDefQuest is modular and you can add your own modules for custom functionality (for example, fighting system). Module is a table and it must have the following fields:\n\n- ```module_name``` – module name string, you will access registered module later by ```defquest.your_module_name.some_function()```\n- ```init(defquest)``` – initialize a module\n- ```final()``` – finalize a module and free up resources\n\n#### ```defquest.act_npc(npc)```\n\nInteract with an NPC. ```npc``` is an NPC identifier. It can be of any type: a string, a Defold hash. Use anything that works best for you to identify NPCs.\n\nThis function will call level's ```on_act_npc``` function, which should return an interaction coroutine. More details on interaction coroutines in the next section and in ```on_act_npc``` function description.\n\n## NPC interaction helper functions\n\n#### ```defquest.show_dialogue(dialogue)```\n\nWhen you need to show a dialogue during an interaction with an NPC, you call this function and pass a dialogue table. Dialogue table format is up to you, because whDefQuest doesn't provide any predefined GUI implementation. The demo project uses the following format:\n\n```lua\n{\n    --{\"Speaker\", \"Phrase\"}\n    {\"Alice\", \"Hi, Bob!\"},\n    {\"Bob\", \"Hi, Alice!\"},\n}\n```\n\nThis function will call corresponding delegate function. When GUI is done with showing a dialogue, you should call ```defquest.on_dialogue_done()``` function. It will resume the interaction coroutine.\n\n#### ```defquest.show_choice(options)```\n\nWhen you need to ask user to pick one of the options in the middle of an interaction, you call this function and pass an options table. Again, there's no predefined format, you can use anything that works best for you. Demo project uses this format:\n\n```lua\n{\n    \"What to answer?\",  -- Prompt\n    \"Yes\",              -- Answer options\n    \"No\",\n}\n```\n\nThis function will call corresponding delegate function. When the answer is selected, you should call ```defquest.on_choice_selected(choice)``` function with the identifier of the selected answer. Again, there's no requirement on data type for the identifier. You can use numbers, strings, or anything else.\n\n#### ```defquest.finish_act()```\n\nWhen you're done interacting with an NPC in the level code, call this function to clean up the interaction coroutine.\n\n#### ```defquest.on_dialogue_done()```\n\nCall this from GUI when you finish showing a dialogue.\n\n#### ```defquest.on_choice_selected(choice)```\n\nCall this from GUI when user selects an answer.\n\n## Inventory module functions\n\nInventory is a built-in module of whDefQuest and provides basic inventory management functions. You can limit the maximum number of items in the inventory by settings ```defquest.inventory.max_items``` field. If the inventory should be unlimited, set it to ```nil``` (it's a default value).\n\n#### ```defquest.inventory.pick_item(item)```\n\nAdd an item to inventory. ```item``` is the item's identifier. Just like NPC identifier, it can be of any type – string, Defold hash, etc.\n\nThis function will call level's ```on_pick_item(item)``` function and delegate's functions:\n\n- ```on_pick_item(item)``` – if the item was successfully picked (good place for the code to remove the picked item from the map)\n- ```on_inventory_full()``` – it the inventory is full\n- ```on_update_inventory(items)``` – to redraw the inventory\n\n#### ```defquest.inventory.remove_item(item)```\n\nRemove an item from inventory. Does nothing if there's no such item. Will call delegate's ```on_update_inventory(items)``` to redraw the inventory.\n\n#### ```defquest.inventory.has_item(item)```\n\nChecks if there's an ```item``` in the inventory. Use this in your level code.\n\n----\n\n## Level table\n\nYou encapsulate level logic in the level table.\n\n#### ```init()```\n\nInitialize a level. This function is optional, whDefQuest checks if it exists.\n\n#### ```final()```\n\nFinalize a level. This function is optional, whDefQuest checks if it exists.\n\n#### ```on_pick_item(defquest, item)```\n\nIf you want to react to image picking, implement this function.\n\n#### ```on_act_npc(defquest, npc)```\n\nShould return an interaction coroutine. This coroutine can use whDefQuest functions ```defquest.show_dialogue(dialogue)``` and ```defquest.show_choice(options)```. These functions pause coroutine to show GUI and resumes it when GUI is done. It allows writing interactions in a linear way, without having to deal with callbacks. When the interaction is done, you must call ```defquest.finish_act()```.\n\n----\n\n## whDefQuest delegate\n\nDelegate is the way for whDefQuest to talk to the game engine (Defold or any other engine, actually).\n\n#### ```on_pick_item(item)```\n\nUse this function to remove picked item from the map, for example, or run some animation.\n\n#### ```on_update_inventory(items)```\n\nUse this function to redraw the inventory. ```items``` is the list of item identifiers.\n\n#### ```on_inventory_full()```\n\nIf you want to indicate the fact that inventory is full, implement this function.\n\n#### ```on_finish_act()```\n\nIа you need to show some animation when an interaction with an NPC is done, implement this function.\n\n#### ```show_dialogue(dialogue)```\n\nShow dialogue. Call ```defquest.on_dialogue_done()``` when you finish.\n\n#### ```show_choice(options)```\n\nShow options to select. Call ```defquest.on_choice_selected(choice)``` when user selects an option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMegus%2Fwhdefquest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMegus%2Fwhdefquest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMegus%2Fwhdefquest/lists"}