init: initial implementation

This commit is contained in:
Erica Marigold 2023-08-15 17:33:32 +05:30
commit 3dd97d152f
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2
14 changed files with 1799 additions and 0 deletions

6
.darklua.json Normal file
View file

@ -0,0 +1,6 @@
{
bundle: {
require_mode: "path",
excludes: ["@lune/**"],
},
}

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
dist/
Packages/

6
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,6 @@
{
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.7.6/"
}
}

4
aftman.toml Normal file
View file

@ -0,0 +1,4 @@
[tools]
lune = "filiptibell/lune@0.7.6"
wally = "upliftgames/wally@0.3.2"
darklua = "seaofvoices/darklua@0.10.2"

8
examples/simple.luau Normal file
View file

@ -0,0 +1,8 @@
local Codenamer = require("../dist/codenamer")
-- Codenamer also allows for optional separators. Here, we tell codenamer to
-- use a space instead of `_`, which is the default separator for words.
local codename = Codenamer.new()
:get_codename(" ")
print("got codename: ", codename)

1
scripts/bundle-prod.sh Executable file
View file

@ -0,0 +1 @@
darklua process src/init.luau dist/codenamer.luau | sed 's/^/[darklua]: /'

33
scripts/install-deps.sh Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -e
declare -A DEPENDENCY_DATA=(
[author]='kdudedev'
[pkgname]='infinite-math'
[version]='1.3.2'
)
INFINITE_MATH_ENTRYPOINT_PATH="Packages/_Index/${DEPENDENCY_DATA[author]}_${DEPENDENCY_DATA[pkgname]}@${DEPENDENCY_DATA[version]}/${DEPENDENCY_DATA[pkgname]}/src/InfiniteMath/init.lua"
echo "[#] Constructed entrypoint file path for ${DEPENDENCY_DATA[pkgname]} -> $INFINITE_MATH_ENTRYPOINT_PATH"
function patch_infinite_math_for_lune() {
[[ -f "$INFINITE_MATH_ENTRYPOINT_PATH" ]] ||
echo "[!] Could not find ${DEPENDENCY_DATA[pkgname]} entrypoint file"
INFINTE_MATH_SRC_DIR="$(dirname $INFINITE_MATH_ENTRYPOINT_PATH)"
INFINITE_MATH_VALUES_DIR="$INFINTE_MATH_SRC_DIR/Values"
mv $INFINITE_MATH_VALUES_DIR/* "$INFINTE_MATH_SRC_DIR/"
rm -rf "$INFINITE_MATH_VALUES_DIR"
sed -i -e 's/local values = script.Values//g' $INFINITE_MATH_ENTRYPOINT_PATH
sed -i -e 's/values.Suffixes/".\/Suffixes.lua"/g' $INFINITE_MATH_ENTRYPOINT_PATH
sed -i -e 's/values.FullNames/".\/FullNames.lua"/g' $INFINITE_MATH_ENTRYPOINT_PATH
}
aftman install | sed 's/^/[aftman]: /' &&
wally install &&
patch_infinite_math_for_lune &&
darklua process $INFINITE_MATH_ENTRYPOINT_PATH "$(dirname $INFINITE_MATH_ENTRYPOINT_PATH)/infinite_math.lua" | sed 's/^/[darklua]: /'

100
src/codenamer.luau Normal file
View file

@ -0,0 +1,100 @@
local INFINITE_MATH_AUTHOR = "kdudedev"
local INFINITE_MATH_PKGNAME = "infinite-math"
local INFINITE_MATH_PKGVER = "1.3.2"
local INFINITE_MATH_PATH = string.format(
"../Packages/_Index/%s@%s/%s/src/InfiniteMath/infinite_math",
INFINITE_MATH_AUTHOR .. "_" .. INFINITE_MATH_PKGNAME,
INFINITE_MATH_PKGVER,
INFINITE_MATH_PKGNAME
)
local InfiniteMath = require(INFINITE_MATH_PATH)
type any_table = { [any]: any }
local Codenamer = {}
Codenamer.Type = "Codenamer"
Codenamer.Interface = {}
Codenamer.Internal = {}
Codenamer.Prototype = {
Dicts = {
Type = "Default",
[1] = require("./dictionaries/adjectives"),
[2] = require("./dictionaries/animals"),
},
}
-- Simple mullbery32 implementation
function Codenamer.Internal.mul32(a: number)
return function()
a += InfiniteMath.new(1831565813)
local t = a:Reverse()
local m = InfiniteMath.new(4294967296)
t = bit32.bxor(t, bit32.rshift(t, 15) * bit32.bor(t, 1))
t = t + bit32.bxor(t, bit32.bxor(t, bit32.rshift(t, 7)), bit32.bor(t, 61))
return ((bit32.rshift(bit32.bxor(t, bit32.rshift(t, 14)), 0)) / m):Reverse()
end
end
function Codenamer.Internal:from_seed(min: number, max: number, seed: number?): number
local gen_seed = self.mul32((os.time() - os.clock() * 1000))
math.randomseed(seed or (gen_seed() * 1000))
return math.random(min, max)
end
function Codenamer.Prototype:to_string(): string
return string.format("%s<%s>", Codenamer.Type, self.Dicts.Type)
end
function Codenamer.Internal:random_word(dict: any_table, seed: number?): string
return dict[self:from_seed(1, #dict, seed)]
end
function Codenamer.Prototype:with_dictionary(dict: any_table)
if self.Dicts["Type"] == "Default" then
self.Dicts = {}
self.Dicts["Type"] = "Custom"
end
table.insert(self.Dicts, dict)
return self
end
function Codenamer.Prototype:get_codename(sep_str: string?, len: number)
local codename = ""
self.Dicts["Type"] = nil
for idx, dict in self.Dicts do
if len and idx - 1 > len then break end
local sep = ""
if idx ~= 1 then
sep = sep_str or "_"
end
codename ..= sep .. self.Internal:random_word(dict)
end
return codename
end
function Codenamer.Interface.new()
Codenamer.Prototype.Internal = Codenamer.Internal
return setmetatable({}, {
__index = Codenamer.Prototype,
__type = Codenamer.Type,
__tostring = function(self)
return self:to_string()
end,
})
end
return Codenamer.Interface

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,357 @@
return {
'aardvark',
'aardwolf',
'albatross',
'alligator',
'alpaca',
'amphibian',
'anaconda',
'angelfish',
'anglerfish',
'ant',
'anteater',
'antelope',
'antlion',
'ape',
'aphid',
'armadillo',
'asp',
'baboon',
'badger',
'bandicoot',
'barnacle',
'barracuda',
'basilisk',
'bass',
'bat',
'bear',
'beaver',
'bedbug',
'bee',
'beetle',
'bird',
'bison',
'blackbird',
'boa',
'boar',
'bobcat',
'bobolink',
'bonobo',
'booby',
'bovid',
'bug',
'butterfly',
'buzzard',
'camel',
'canid',
'canidae',
'capybara',
'cardinal',
'caribou',
'carp',
'cat',
'caterpillar',
'catfish',
'catshark',
'cattle',
'centipede',
'cephalopod',
'chameleon',
'cheetah',
'chickadee',
'chicken',
'chimpanzee',
'chinchilla',
'chipmunk',
'cicada',
'clam',
'clownfish',
'cobra',
'cockroach',
'cod',
'condor',
'constrictor',
'coral',
'cougar',
'cow',
'coyote',
'crab',
'crane',
'crawdad',
'crayfish',
'cricket',
'crocodile',
'crow',
'cuckoo',
'damselfly',
'deer',
'dingo',
'dinosaur',
'dog',
'dolphin',
'donkey',
'dormouse',
'dove',
'dragon',
'dragonfly',
'duck',
'eagle',
'earthworm',
'earwig',
'echidna',
'eel',
'egret',
'elephant',
'elk',
'emu',
'ermine',
'falcon',
'felidae',
'ferret',
'finch',
'firefly',
'fish',
'flamingo',
'flea',
'fly',
'flyingfish',
'fowl',
'fox',
'frog',
'galliform',
'gamefowl',
'gayal',
'gazelle',
'gecko',
'gerbil',
'gibbon',
'giraffe',
'goat',
'goldfish',
'goose',
'gopher',
'gorilla',
'grasshopper',
'grouse',
'guan',
'guanaco',
'guineafowl',
'gull',
'guppy',
'haddock',
'halibut',
'hamster',
'hare',
'harrier',
'hawk',
'hedgehog',
'heron',
'herring',
'hippopotamus',
'hookworm',
'hornet',
'horse',
'hoverfly',
'hummingbird',
'hyena',
'iguana',
'impala',
'jackal',
'jaguar',
'jay',
'jellyfish',
'junglefowl',
'kangaroo',
'kingfisher',
'kite',
'kiwi',
'koala',
'koi',
'krill',
'ladybug',
'lamprey',
'landfowl',
'lark',
'leech',
'lemming',
'lemur',
'leopard',
'leopon',
'limpet',
'lion',
'lizard',
'llama',
'lobster',
'locust',
'loon',
'louse',
'lungfish',
'lynx',
'macaw',
'mackerel',
'magpie',
'mammal',
'manatee',
'mandrill',
'marlin',
'marmoset',
'marmot',
'marsupial',
'marten',
'mastodon',
'meadowlark',
'meerkat',
'mink',
'minnow',
'mite',
'mockingbird',
'mole',
'mollusk',
'mongoose',
'monkey',
'moose',
'mosquito',
'moth',
'mouse',
'mule',
'muskox',
'narwhal',
'newt',
'nightingale',
'ocelot',
'octopus',
'opossum',
'orangutan',
'orca',
'ostrich',
'otter',
'owl',
'ox',
'panda',
'panther',
'parakeet',
'parrot',
'parrotfish',
'partridge',
'peacock',
'peafowl',
'pelican',
'penguin',
'perch',
'pheasant',
'pig',
'pigeon',
'pike',
'pinniped',
'piranha',
'planarian',
'platypus',
'pony',
'porcupine',
'porpoise',
'possum',
'prawn',
'primate',
'ptarmigan',
'puffin',
'puma',
'python',
'quail',
'quelea',
'quokka',
'rabbit',
'raccoon',
'rat',
'rattlesnake',
'raven',
'reindeer',
'reptile',
'rhinoceros',
'roadrunner',
'rodent',
'rook',
'rooster',
'roundworm',
'sailfish',
'salamander',
'salmon',
'sawfish',
'scallop',
'scorpion',
'seahorse',
'shark',
'sheep',
'shrew',
'shrimp',
'silkworm',
'silverfish',
'skink',
'skunk',
'sloth',
'slug',
'smelt',
'snail',
'snake',
'snipe',
'sole',
'sparrow',
'spider',
'spoonbill',
'squid',
'squirrel',
'starfish',
'stingray',
'stoat',
'stork',
'sturgeon',
'swallow',
'swan',
'swift',
'swordfish',
'swordtail',
'tahr',
'takin',
'tapir',
'tarantula',
'tarsier',
'termite',
'tern',
'thrush',
'tick',
'tiger',
'tiglon',
'toad',
'tortoise',
'toucan',
'trout',
'tuna',
'turkey',
'turtle',
'tyrannosaurus',
'unicorn',
'urial',
'vicuna',
'viper',
'vole',
'vulture',
'wallaby',
'walrus',
'warbler',
'wasp',
'weasel',
'whale',
'whippet',
'whitefish',
'wildcat',
'wildebeest',
'wildfowl',
'wolf',
'wolverine',
'wombat',
'woodpecker',
'worm',
'wren',
'xerinae',
'yak',
'zebra',
}

View file

@ -0,0 +1,54 @@
return {
'amaranth',
'amber',
'amethyst',
'apricot',
'aqua',
'aquamarine',
'azure',
'beige',
'black',
'blue',
'blush',
'bronze',
'brown',
'chocolate',
'coffee',
'copper',
'coral',
'crimson',
'cyan',
'emerald',
'fuchsia',
'gold',
'gray',
'green',
'harlequin',
'indigo',
'ivory',
'jade',
'lavender',
'lime',
'magenta',
'maroon',
'moccasin',
'olive',
'orange',
'peach',
'pink',
'plum',
'purple',
'red',
'rose',
'salmon',
'sapphire',
'scarlet',
'silver',
'tan',
'teal',
'tomato',
'turquoise',
'violet',
'white',
'yellow',
}

3
src/init.luau Normal file
View file

@ -0,0 +1,3 @@
local codenamer = require("./codenamer")
return codenamer

13
wally.lock Normal file
View file

@ -0,0 +1,13 @@
# This file is automatically @generated by Wally.
# It is not intended for manual editing.
registry = "test"
[[package]]
name = "compeydev/codenamer"
version = "0.1.0"
dependencies = [["infinite-math", "kdudedev/infinite-math@1.3.2"]]
[[package]]
name = "kdudedev/infinite-math"
version = "1.3.2"
dependencies = []

8
wally.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "compeydev/codenamer"
version = "0.1.0"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
[dependencies]
infinite-math = "kdudedev/infinite-math@1.3.2"