Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/indiesoftby/defold-unique-names-generator
A simple way to generate unique names in your Defold games.
https://github.com/indiesoftby/defold-unique-names-generator
defold defold-library lua
Last synced: 4 months ago
JSON representation
A simple way to generate unique names in your Defold games.
- Host: GitHub
- URL: https://github.com/indiesoftby/defold-unique-names-generator
- Owner: indiesoftby
- License: mit
- Created: 2024-09-13T13:07:13.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-13T13:32:15.000Z (5 months ago)
- Last Synced: 2024-09-29T15:22:31.465Z (4 months ago)
- Topics: defold, defold-library, lua
- Language: Lua
- Homepage:
- Size: 25.4 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-defold - Unique Names Generator
README
# Unique Names Generator for Defold
This module provides a simple way to generate unique names in your Defold games. It includes a collection of dictionaries for different types of words, such as adjectives, animals, names, colors, and numbers.
## Installation
To use this library in your Defold project, add the following URL to your `game.project` dependencies:
https://github.com/indiesoftby/defold-unique-names-generator/archive/main.zip
## Usage
```lua
local names_generator = require("unique_names_generator.names_generator")local adjectives = require("unique_names_generator.dictionaries.adjectives")
local animals = require("unique_names_generator.dictionaries.animals")
local colors = require("unique_names_generator.dictionaries.colors")
local numbers = require("unique_names_generator.dictionaries.numbers")function init(self)
-- Using default dictionaries:
local generator = names_generator.new({
dictionaries = {
colors,
adjectives,
animals,
numbers({ min = 100, max = 999 })
},
style = "capital",
separator = ""
})-- Generate 3 names:
print(generator.generate())
print(generator.generate())
print(generator.generate())-- Using your own dictionaries:
local config = {
dictionaries = {
{"stylish", "awesome", "fantastic"},
{"boy", "girl", "cat"},
},
separator = "_",
style = "lower_case",
random = math.random -- you can pass your own random function if you want
}local generator2 = names_generator.new(config)
print(generator2.generate())
end
```## API Reference
### `names_generator.new(config)`
Creates a new `generator` instance.
**Parameters:**
- `config` (table): Configuration options for the generator.
- `dictionaries` (table): Array of dictionaries to use for name generation.
- `separator` (string, optional): Separator to use between words. Default: "_"
- `style` (string, optional): Style of generated words ("lower_case", "upper_case", or "capital"). Default: ""
- `random` (function, optional): Random function to use. Default: `math.random`**Returns:**
- `table`: A table with the `generate` function to create unique names.### `generator:generate()`
Generates a unique name.
**Returns:**
- `string`: A generated unique name.## License
This library is released under the MIT License. See [LICENSE](LICENSE.md) for details.
It's based on the [unique-names-generator](https://github.com/andreasonny83/unique-names-generator) JavaScript library.