Skip to content

Commit

Permalink
Initial workshop stage with some tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Deseteral committed Jul 8, 2023
1 parent 500e205 commit 218a9ae
Show file tree
Hide file tree
Showing 17 changed files with 1,125 additions and 116 deletions.
211 changes: 211 additions & 0 deletions Source/game/messages.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
-- Lua Library inline imports
local __TS__StringSplit
do
local sub = string.sub
local find = string.find
function __TS__StringSplit(source, separator, limit)
if limit == nil then
limit = 4294967295
end
if limit == 0 then
return {}
end
local result = {}
local resultIndex = 1
if separator == nil or separator == "" then
for i = 1, #source do
result[resultIndex] = sub(source, i, i)
resultIndex = resultIndex + 1
end
else
local currentPos = 1
while resultIndex <= limit do
local startPos, endPos = find(source, separator, currentPos, true)
if not startPos then
break
end
result[resultIndex] = sub(source, currentPos, startPos - 1)
resultIndex = resultIndex + 1
currentPos = endPos + 1
end
if resultIndex <= limit then
result[resultIndex] = sub(source, currentPos)
end
end
return result
end
end

local function __TS__ArrayFilter(self, callbackfn, thisArg)
local result = {}
local len = 0
for i = 1, #self do
if callbackfn(thisArg, self[i], i - 1, self) then
len = len + 1
result[len] = self[i]
end
end
return result
end
-- End of Lua Library inline imports
local ____exports = {}
local function choice(self, list)
local idx = randomRange(nil, 0, #list - 1)
return list[idx + 1]
end
local function split(self, text)
local tokens = __TS__StringSplit(text, " ")
local msg = {}
local line = tokens[1]
do
local idx = 1
while idx < #tokens do
local token = tokens[idx + 1]
if #line + 1 + #token <= 37 then
line = line .. " " .. token
else
msg[#msg + 1] = line
line = token
end
idx = idx + 1
end
end
msg[#msg + 1] = line
return msg
end
function ____exports.newClientMessage(self, recipe)
local greetings = {
"Hello!",
"Hey!",
"Good morning!",
"Hello there!",
"Morning!",
"Howdy!",
"Good to see you!",
"Ahoy!",
"Hello stranger!"
}
local middle = {
"How are you?",
"It's so cold today.",
"Beautiful day, isn't it?",
"It looks like it's going to snow",
"We couldn't ask for a nicer day, could we?",
"Looking forward to the weekend?",
"I can't believe how busy we are today!",
"I didn't think it would be so busy today."
}
local ____end = {
("Can you make me some " .. recipe.name) .. "?",
("I'd like " .. recipe.name) .. ", please.",
("Could I have a " .. recipe.name) .. ", please?",
("How much for " .. recipe.name) .. "?",
("I need some " .. recipe.name) .. ".",
("Do you sell " .. recipe.name) .. "?",
("I'll take " .. recipe.name) .. ".",
("I have to buy some " .. recipe.name) .. "."
}
local msg = table.concat(
__TS__ArrayFilter(
{
choice(nil, greetings),
math.random() < 0.5 and choice(nil, middle) or "",
choice(nil, ____end)
},
function(____, s) return #s > 0 end
),
" "
)
return {
text = split(nil, msg),
rightSide = false
}
end
function ____exports.orderCompleteMessage(self, recipe)
local starters = {"There you go!", "Sir!", "Madame!"}
local middle = {
("Your " .. recipe.name) .. ".",
recipe.name .. " for you.",
("One " .. recipe.name) .. " for you.",
("One " .. recipe.name) .. ".",
"Your order.",
"This is for you.",
"I have your order!",
""
}
local ____end = {
"Bye!",
"Goodbye!",
"Bye for now!",
"See you!",
"Be seeing you!",
"See you soon!",
"Cheerio!",
"Catch you later!"
}
local msg = table.concat(
__TS__ArrayFilter(
{
math.random() < 0.5 and choice(nil, starters) or "",
choice(nil, middle),
choice(nil, ____end)
},
function(____, s) return #s > 0 end
),
" "
)
return {
text = split(nil, msg),
rightSide = true
}
end
function ____exports.clientGoodbyeMessasge(self)
local list = {
"Thank you!",
"Bye!",
"See you later!",
"Perfect! Ciao!",
"Awesome, thank you so much!"
}
return {
text = split(
nil,
choice(nil, list)
),
rightSide = true
}
end
function ____exports.recipeDoesNotExistMessage(self)
local list = {"What is that? Ugh!", "Yuck!", "Bleh! What have I done?!", "Oh no! How did that happen?!"}
return {
text = split(
nil,
choice(nil, list)
),
rightSide = true
}
end
function ____exports.recipeWithoutOrderMessage(self)
local list = {"This is good, but why I've made this?", "Nobody wants this.", "Good potion, bad thinking.", "I've messed up some orders."}
return {
text = split(
nil,
choice(nil, list)
),
rightSide = true
}
end
function ____exports.dayOverMessage(self)
return {
text = split(nil, "It's getting late. Time to close the store."),
rightSide = true
}
end
newClientMessage = ____exports.newClientMessage
orderCompleteMessage = ____exports.orderCompleteMessage
clientGoodbyeMessasge = ____exports.clientGoodbyeMessasge
recipeDoesNotExistMessage = ____exports.recipeDoesNotExistMessage
recipeWithoutOrderMessage = ____exports.recipeWithoutOrderMessage
dayOverMessage = ____exports.dayOverMessage
return ____exports
78 changes: 78 additions & 0 deletions Source/game/recipes.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
-- Lua Library inline imports
local function __TS__ArrayForEach(self, callbackFn, thisArg)
for i = 1, #self do
callbackFn(thisArg, self[i], i - 1, self)
end
end

local function __TS__ArrayFindIndex(self, callbackFn, thisArg)
for i = 1, #self do
if callbackFn(thisArg, self[i], i - 1, self) then
Expand Down Expand Up @@ -88,6 +94,74 @@ local function __TS__ArraySplice(self, ...)
end
-- End of Lua Library inline imports
local ____exports = {}
function ____exports.getIngredientIcon(self, ingredient)
repeat
local ____switch3 = ingredient
local ____cond3 = ____switch3 == Ingredient.HERB
if ____cond3 then
return Textures.herbTexture.normal
end
____cond3 = ____cond3 or ____switch3 == Ingredient.MUSHROOM
if ____cond3 then
return Textures.mushroomTexture.normal
end
____cond3 = ____cond3 or ____switch3 == Ingredient.STONE
if ____cond3 then
return Textures.stoneTexture.normal
end
____cond3 = ____cond3 or ____switch3 == Ingredient.GOLD
if ____cond3 then
return Textures.stoneTexture.inverted
end
____cond3 = ____cond3 or ____switch3 == Ingredient.FLOWER
if ____cond3 then
return Textures.flowerTexture.normal
end
do
return Textures.xTexture.normal
end
until true
end
function ____exports.getIngredientActionIcon(self, action)
repeat
local ____switch5 = action
local ____cond5 = ____switch5 == IngredientAction.CUTTING
if ____cond5 then
return Textures.knifeTexture.normal
end
____cond5 = ____cond5 or ____switch5 == IngredientAction.GRIDING
if ____cond5 then
return Textures.mortarTexture.normal
end
____cond5 = ____cond5 or ____switch5 == IngredientAction.BURNING
if ____cond5 then
return Textures.fireTexture.normal
end
____cond5 = ____cond5 or ____switch5 == IngredientAction.ENCHANTING
if ____cond5 then
return Textures.spellTexture.normal
end
do
return Textures.xTexture.normal
end
until true
end
function ____exports.drawPreparedIngredientRow(self, pi, x, y)
____exports.getIngredientIcon(nil, pi.ingredient):draw(x, y)
Textures.xTexture.normal:draw(x + 16, y)
____exports.getIngredientActionIcon(nil, pi.action):draw(x + 16 * 2, y)
end
function ____exports.drawRecipe(self, recipe, x, y)
Font:draw(recipe.name, x, y)
__TS__ArrayForEach(
recipe.ingredients,
function(____, ing, idx)
local xx = x + 5
local yy = y + 40 + (16 + 5) * idx
____exports.drawPreparedIngredientRow(nil, ing, xx, yy)
end
)
end
function ____exports.generateRecipes(self)
local recipes = {}
local namePool = {table.unpack(POTION_NAMES)}
Expand Down Expand Up @@ -138,5 +212,9 @@ function ____exports.generateRecipes(self)
)
return recipes
end
getIngredientIcon = ____exports.getIngredientIcon
getIngredientActionIcon = ____exports.getIngredientActionIcon
drawPreparedIngredientRow = ____exports.drawPreparedIngredientRow
drawRecipe = ____exports.drawRecipe
generateRecipes = ____exports.generateRecipes
return ____exports
Loading

0 comments on commit 218a9ae

Please sign in to comment.