Lua format.

This commit is contained in:
Daniel Schmidt 2023-05-16 10:45:31 +02:00
parent cadfb5c135
commit b2fdbee545
35 changed files with 227 additions and 112 deletions

View File

@ -11,4 +11,4 @@ register_artifact("BAG_OF_HOLDING", {
return nil
end
}
});
});

View File

@ -11,4 +11,4 @@ register_artifact("DEFLECTOR_SHIELD", {
return nil
end
}
});
});

View File

@ -11,4 +11,4 @@ register_artifact("GIGANTIC_STRENGTH", {
return nil
end
}
});
});

View File

@ -11,4 +11,4 @@ register_artifact("GOLD_CONVERTER", {
return nil
end
}
});
});

View File

@ -11,4 +11,4 @@ register_artifact("HOLY_GRAIL", {
return nil
end
}
});
});

View File

@ -9,4 +9,4 @@ register_artifact("JUICY_FRUIT", {
return nil
end
}
});
});

View File

@ -9,4 +9,4 @@ register_artifact("RADIANT_SEED", {
return nil
end
}
});
});

View File

@ -11,4 +11,4 @@ register_artifact("REPULSION_STONE", {
return nil
end
}
});
});

View File

@ -13,4 +13,4 @@ register_artifact("SHORT_RADIANCE", {
return nil
end
}
});
});

View File

@ -11,4 +11,4 @@ register_artifact("SPIKED_PLANT", {
return nil
end
}
});
});

View File

@ -15,4 +15,4 @@ register_card("KILL", {
return nil
end
}
})
})

View File

@ -3,7 +3,7 @@ register_card("BERSERKER_RAGE", {
description = "Gain " .. highlight("3 energy") .. ", but take 30% (-10% per level) of your HP as damage.",
state = function(ctx)
return "Gain " .. highlight("3 energy") .. ", but take " .. highlight(tostring(30 - ctx.level * 10) .. "%") .. " (" ..
tostring(get_player().hp * (0.3 - ctx.level * 0.1)) .. ") of your HP as damage."
tostring(get_player().hp * (0.3 - ctx.level * 0.1)) .. ") of your HP as damage."
end,
max_level = 0,
color = "#d8a448",
@ -17,4 +17,4 @@ register_card("BERSERKER_RAGE", {
return nil
end
}
})
})

View File

@ -15,4 +15,4 @@ register_card("BLOCK", {
return nil
end
}
})
})

View File

@ -46,4 +46,4 @@ register_card("BLOCK_SPIKES", {
return nil
end
}
})
})

View File

@ -15,4 +15,4 @@ register_card("COMBINED_SHOT", {
return nil
end
}
})
})

View File

@ -15,4 +15,4 @@ register_card("FEAR", {
return nil
end
}
})
})

View File

@ -15,4 +15,4 @@ register_card("MELEE_HIT", {
return nil
end
}
})
})

View File

@ -3,7 +3,7 @@ register_card("RADIANT_SEED", {
description = "Inflict 10 (+2 for each upgrade) damage to all enemies, but also causes 5 (-2 for each upgrade) damage to the caster.",
state = function(ctx)
return "Inflict " .. highlight(10 + ctx.level * 2) .. " damage to all enemies, but also causes " .. highlight(5 - ctx.level * 2) ..
" damage to the caster."
" damage to the caster."
end,
max_level = 1,
color = "#82c93e",
@ -19,4 +19,4 @@ register_card("RADIANT_SEED", {
return nil
end
}
})
})

View File

@ -15,4 +15,4 @@ register_card("RUPTURE", {
return nil
end
}
})
})

View File

@ -1,10 +1,10 @@
register_card("SHIELD_BASH", {
name = "Shield Bash",
description = "Deal 4 (+2 for each upgrade) damage to the enemy and gain " .. highlight("block") ..
" status effect equal to the damage dealt.",
" status effect equal to the damage dealt.",
state = function(ctx)
return "Deal " .. highlight(4 + ctx.level * 2) .. " damage to the enemy and gain " .. highlight("block") ..
" status effect equal to the damage dealt."
" status effect equal to the damage dealt."
end,
max_level = 1,
color = "#ff5722",
@ -18,4 +18,4 @@ register_card("SHIELD_BASH", {
return nil
end
}
})
})

View File

@ -34,4 +34,4 @@ register_enemy("CLEAN_BOT", {
return nil
end
}
})
})

View File

@ -62,4 +62,4 @@ register_status_effect("BLEED", {
return nil
end
}
})
})

View File

@ -5,7 +5,6 @@
---
--- Distributed under the MIT/X11 License. See COPYING.md for more details.
---
local exports = {}
local methods = {}
@ -48,20 +47,16 @@ local iterator_mt = {
-- usually called by for-in loop
__call = function(self, param, state)
return self.gen(param, state)
end;
end,
__tostring = function(self)
return '<generator>'
end;
end,
-- add all exported methods
__index = methods;
__index = methods
}
local wrap = function(gen, param, state)
return setmetatable({
gen = gen,
param = param,
state = state
}, iterator_mt), param, state
return setmetatable({ gen = gen, param = param, state = state }, iterator_mt), param, state
end
exports.wrap = wrap
@ -124,8 +119,7 @@ local rawiter = function(obj, param, state)
end
return string_gen, obj, 0
end
error(string.format('object %s of type "%s" is not iterable',
obj, type(obj)))
error(string.format('object %s of type "%s" is not iterable', obj, type(obj)))
end
local iter = function(obj, param, state)
@ -221,9 +215,9 @@ local range = function(start, stop, step)
assert(step ~= 0, "step must not be zero")
if (step > 0) then
return wrap(range_gen, {stop, step}, start - step)
return wrap(range_gen, { stop, step }, start - step)
elseif (step < 0) then
return wrap(range_rev_gen, {stop, step}, start - step)
return wrap(range_rev_gen, { stop, step }, start - step)
end
end
exports.range = range
@ -244,7 +238,7 @@ local duplicate = function(...)
if select('#', ...) <= 1 then
return wrap(duplicate_gen, select(1, ...), 0)
else
return wrap(duplicate_table_gen, {...}, 0)
return wrap(duplicate_table_gen, { ... }, 0)
end
end
exports.duplicate = duplicate
@ -287,7 +281,7 @@ local rands = function(n, m)
assert(type(m) == "number", "invalid second arg to rands")
end
assert(n < m, "empty interval")
return wrap(rands_gen, {n, m - 1}, 0)
return wrap(rands_gen, { n, m - 1 }, 0)
end
exports.rands = rands
@ -307,7 +301,7 @@ local nth = function(n, gen_x, param_x, state_x)
return nil
end
end
for i=1,n-1,1 do
for i = 1, n - 1, 1 do
state_x = gen_x(param_x, state_x)
if state_x == nil then
return nil
@ -349,7 +343,7 @@ local take_n_gen_x = function(i, state_x, ...)
if state_x == nil then
return nil
end
return {i, state_x}, ...
return { i, state_x }, ...
end
local take_n_gen = function(param, state)
@ -363,7 +357,7 @@ end
local take_n = function(n, gen, param, state)
assert(n >= 0, "invalid first argument to take_n")
return wrap(take_n_gen, {n, gen, param}, {0, state})
return wrap(take_n_gen, { n, gen, param }, { 0, state })
end
methods.take_n = method1(take_n)
exports.take_n = export1(take_n)
@ -382,7 +376,7 @@ end
local take_while = function(fun, gen, param, state)
assert(type(fun) == "function", "invalid first argument to take_while")
return wrap(take_while_gen, {fun, gen, param}, state)
return wrap(take_while_gen, { fun, gen, param }, state)
end
methods.take_while = method1(take_while)
exports.take_while = export1(take_while)
@ -400,7 +394,7 @@ exports.take = export1(take)
local drop_n = function(n, gen, param, state)
assert(n >= 0, "invalid first argument to drop_n")
local i
for i=1,n,1 do
for i = 1, n, 1 do
state = gen(param, state)
if state == nil then
return wrap(nil_gen, nil, nil)
@ -444,8 +438,7 @@ methods.drop = method1(drop)
exports.drop = export1(drop)
local split = function(n_or_fun, gen_x, param_x, state_x)
return take(n_or_fun, gen_x, param_x, state_x),
drop(n_or_fun, gen_x, param_x, state_x)
return take(n_or_fun, gen_x, param_x, state_x), drop(n_or_fun, gen_x, param_x, state_x)
end
methods.split = method1(split)
exports.split = export1(split)
@ -486,13 +479,13 @@ local indexes_gen = function(param, state)
end
i = i + 1
if r == x then
return {i, state_x}, i
return { i, state_x }, i
end
end
end
local indexes = function(x, gen, param, state)
return wrap(indexes_gen, {x, gen, param}, {0, state})
return wrap(indexes_gen, { x, gen, param }, { 0, state })
end
methods.indexes = method1(indexes)
exports.indexes = export1(indexes)
@ -509,7 +502,9 @@ exports.elem_indices = exports.indexes
local filter1_gen = function(fun, gen_x, param_x, state_x, a)
while true do
if state_x == nil or fun(a) then break; end
if state_x == nil or fun(a) then
break
end
state_x, a = gen_x(param_x, state_x)
end
return state_x, a
@ -545,7 +540,7 @@ local filter_gen = function(param, state_x)
end
local filter = function(fun, gen, param, state)
return wrap(filter_gen, {fun, gen, param}, state)
return wrap(filter_gen, { fun, gen, param }, state)
end
methods.filter = method1(filter)
exports.filter = export1(filter)
@ -555,7 +550,9 @@ exports.remove_if = exports.filter
local grep = function(fun_or_regexp, gen, param, state)
local fun = fun_or_regexp
if type(fun_or_regexp) == "string" then
fun = function(x) return string.find(x, fun_or_regexp) ~= nil end
fun = function(x)
return string.find(x, fun_or_regexp) ~= nil
end
end
return filter(fun, gen, param, state)
end
@ -566,8 +563,7 @@ local partition = function(fun, gen, param, state)
local neg_fun = function(...)
return not fun(...)
end
return filter(fun, gen, param, state),
filter(neg_fun, gen, param, state)
return filter(fun, gen, param, state), filter(neg_fun, gen, param, state)
end
methods.partition = method1(partition)
exports.partition = export1(partition)
@ -587,7 +583,7 @@ local foldl = function(fun, start, gen_x, param_x, state_x)
while true do
state_x, start = foldl_call(fun, start, gen_x(param_x, state_x))
if state_x == nil then
break;
break
end
end
return start
@ -622,7 +618,7 @@ local is_prefix_of = function(iter_x, iter_y)
local gen_y, param_y, state_y = iter(iter_y)
local r_x, r_y
for i=1,10,1 do
for i = 1, 10, 1 do
state_x, r_x = gen_x(param_x, state_x)
state_y, r_y = gen_y(param_y, state_y)
if state_x == nil then
@ -685,11 +681,19 @@ methods.product = method0(product)
exports.product = export0(product)
local min_cmp = function(m, n)
if n < m then return n else return m end
if n < m then
return n
else
return m
end
end
local max_cmp = function(m, n)
if n > m then return n else return m end
if n > m then
return n
else
return m
end
end
local min = function(gen, param, state)
@ -810,7 +814,7 @@ local map_gen = function(param, state)
end
local map = function(fun, gen, param, state)
return wrap(map_gen, {gen, param, fun}, state)
return wrap(map_gen, { gen, param, fun }, state)
end
methods.map = method1(map)
exports.map = export1(map)
@ -819,7 +823,7 @@ local enumerate_gen_call = function(state, i, state_x, ...)
if state_x == nil then
return nil
end
return {i + 1, state_x}, i, ...
return { i + 1, state_x }, i, ...
end
local enumerate_gen = function(param, state)
@ -829,7 +833,7 @@ local enumerate_gen = function(param, state)
end
local enumerate = function(gen, param, state)
return wrap(enumerate_gen, {gen, param}, {1, state})
return wrap(enumerate_gen, { gen, param }, { 1, state })
end
methods.enumerate = method0(enumerate)
exports.enumerate = export0(enumerate)
@ -838,14 +842,14 @@ local intersperse_call = function(i, state_x, ...)
if state_x == nil then
return nil
end
return {i + 1, state_x}, ...
return { i + 1, state_x }, ...
end
local intersperse_gen = function(param, state)
local x, gen_x, param_x = param[1], param[2], param[3]
local i, state_x = state[1], state[2]
if i % 2 == 1 then
return {i + 1, state_x}, x
return { i + 1, state_x }, x
else
return intersperse_call(i, gen_x(param_x, state_x))
end
@ -853,7 +857,7 @@ end
-- TODO: interperse must not add x to the tail
local intersperse = function(x, gen, param, state)
return wrap(intersperse_gen, {x, gen, param}, {0, state})
return wrap(intersperse_gen, { x, gen, param }, { 0, state })
end
methods.intersperse = method1(intersperse)
exports.intersperse = export1(intersperse)
@ -888,8 +892,7 @@ local numargs = function(...)
if n >= 3 then
-- Fix last argument
local it = select(n - 2, ...)
if type(it) == 'table' and getmetatable(it) == iterator_mt and
it.param == select(n - 1, ...) and it.state == select(n, ...) then
if type(it) == 'table' and getmetatable(it) == iterator_mt and it.param == select(n - 1, ...) and it.state == select(n, ...) then
return n - 2
end
end
@ -905,7 +908,7 @@ local zip = function(...)
local state = { [n] = 0 }
local i, gen_x, param_x, state_x
for i=1,n,1 do
for i = 1, n, 1 do
local it = select(n - i + 1, ...)
gen_x, param_x, state_x = rawiter(it)
param[2 * i - 1] = gen_x
@ -932,7 +935,7 @@ local cycle_gen = function(param, state_x)
end
local cycle = function(gen, param, state)
return wrap(cycle_gen, {gen, param, state}, deepcopy(state))
return wrap(cycle_gen, { gen, param, state }, deepcopy(state))
end
methods.cycle = method0(cycle)
exports.cycle = export0(cycle)
@ -947,9 +950,9 @@ local chain_gen_r2 = function(param, state, state_x, ...)
return nil
end
local state_x = param[3 * i]
return chain_gen_r1(param, {i, state_x})
return chain_gen_r1(param, { i, state_x })
end
return {state[1], state_x}, ...
return { state[1], state_x }, ...
end
chain_gen_r1 = function(param, state)
@ -966,7 +969,7 @@ local chain = function(...)
local param = { [3 * n] = 0 }
local i, gen_x, param_x, state_x
for i=1,n,1 do
for i = 1, n, 1 do
local elem = select(i, ...)
gen_x, param_x, state_x = iter(elem)
param[3 * i - 2] = gen_x
@ -974,7 +977,7 @@ local chain = function(...)
param[3 * i] = state_x
end
return wrap(chain_gen_r1, param, {1, param[3]})
return wrap(chain_gen_r1, param, { 1, param[3] })
end
methods.chain = chain
exports.chain = chain
@ -987,45 +990,95 @@ local operator = {
----------------------------------------------------------------------------
-- Comparison operators
----------------------------------------------------------------------------
lt = function(a, b) return a < b end,
le = function(a, b) return a <= b end,
eq = function(a, b) return a == b end,
ne = function(a, b) return a ~= b end,
ge = function(a, b) return a >= b end,
gt = function(a, b) return a > b end,
lt = function(a, b)
return a < b
end,
le = function(a, b)
return a <= b
end,
eq = function(a, b)
return a == b
end,
ne = function(a, b)
return a ~= b
end,
ge = function(a, b)
return a >= b
end,
gt = function(a, b)
return a > b
end,
----------------------------------------------------------------------------
-- Arithmetic operators
----------------------------------------------------------------------------
add = function(a, b) return a + b end,
div = function(a, b) return a / b end,
floordiv = function(a, b) return math.floor(a/b) end,
add = function(a, b)
return a + b
end,
div = function(a, b)
return a / b
end,
floordiv = function(a, b)
return math.floor(a / b)
end,
intdiv = function(a, b)
local q = a / b
if a >= 0 then return math.floor(q) else return math.ceil(q) end
if a >= 0 then
return math.floor(q)
else
return math.ceil(q)
end
end,
mod = function(a, b)
return a % b
end,
mul = function(a, b)
return a * b
end,
neq = function(a)
return -a
end,
unm = function(a)
return -a
end, -- an alias
pow = function(a, b)
return a ^ b
end,
sub = function(a, b)
return a - b
end,
truediv = function(a, b)
return a / b
end,
mod = function(a, b) return a % b end,
mul = function(a, b) return a * b end,
neq = function(a) return -a end,
unm = function(a) return -a end, -- an alias
pow = function(a, b) return a ^ b end,
sub = function(a, b) return a - b end,
truediv = function(a, b) return a / b end,
----------------------------------------------------------------------------
-- String operators
----------------------------------------------------------------------------
concat = function(a, b) return a..b end,
len = function(a) return #a end,
length = function(a) return #a end, -- an alias
concat = function(a, b)
return a .. b
end,
len = function(a)
return #a
end,
length = function(a)
return #a
end, -- an alias
----------------------------------------------------------------------------
-- Logical operators
----------------------------------------------------------------------------
land = function(a, b) return a and b end,
lor = function(a, b) return a or b end,
lnot = function(a) return not a end,
truth = function(a) return not not a end,
land = function(a, b)
return a and b
end,
lor = function(a, b)
return a or b
end,
lnot = function(a)
return not a
end,
truth = function(a)
return not not a
end
}
exports.operator = operator
methods.operator = operator
@ -1052,7 +1105,7 @@ setmetatable(exports, {
rawset(_G, k, v)
end
end
end,
end
})
return exports
return exports

View File

@ -19,4 +19,4 @@ register_status_effect("BLOCK", {
return ctx.damage
end
}
})
})

View File

@ -15,4 +15,4 @@ register_status_effect("BURN", {
return nil
end
}
})
})

View File

@ -14,4 +14,4 @@ register_status_effect("FEAR", {
return true
end
}
})
})

View File

@ -17,4 +17,4 @@ register_status_effect("STRENGTH", {
return ctx.damage
end
}
})
})

View File

@ -17,4 +17,4 @@ register_status_effect("VULNERABLE", {
return ctx.damage
end
}
})
})

View File

@ -17,4 +17,4 @@ register_status_effect("WEAKEN", {
return ctx.damage
end
}
})
})

View File

@ -35,4 +35,4 @@ After some effort, you manage to open the door and find yourself in a small room
return GAME_STATE_FIGHT
end
})
})

View File

@ -0,0 +1,31 @@
stage_1_bio_kingdom = {
fights = { { "RUST_MITE", "RUST_MITE", "RUST_MITE" }, { "SHADOW_ASSASSIN", "SHADOW_ASSASSIN" }, { "SHADOW_ASSASSIN" } }
}
register_story_teller("STAGE_1", {
active = function(ctx)
if had_event("BIO_KINGDOM") then
return 1
end
return 0
end,
decide = function(ctx)
local stage = get_stages_cleared()
if stage == 10 then
-- BOSS
end
-- 10% chance to find a random artifact
if math.random() < 0.1 then
set_event(create_artifact_choice({ random_artifact(get_merchant_gold_max()), random_artifact(get_merchant_gold_max()) }))
end
local choice = stage_1_bio_kingdom.fights[math.random(#stage_1_bio_kingdom.fights)]
for _, v in ipairs(choice) do
add_actor_by_enemy(v)
end
return GAME_STATE_FIGHT
end
})

View File

@ -1,8 +1,8 @@
stage_1 = { fights = { { "RUST_MITE", "RUST_MITE", "RUST_MITE" }, { "SHADOW_ASSASSIN", "SHADOW_ASSASSIN" }, { "SHADOW_ASSASSIN" } } }
stage_1_the_core = { fights = { { "RUST_MITE", "RUST_MITE", "RUST_MITE" }, { "CLEAN_BOT", "CLEAN_BOT" } } }
register_story_teller("STAGE_1", {
active = function(ctx)
if had_events_any(stage_1_init_events) then
if had_event("THE_CORE") then
return 1
end
return 0
@ -19,11 +19,11 @@ register_story_teller("STAGE_1", {
set_event(create_artifact_choice({ random_artifact(get_merchant_gold_max()), random_artifact(get_merchant_gold_max()) }))
end
local choice = stage_1.fights[math.random(#stage_2.fights)]
local choice = stage_1_the_core.fights[math.random(#stage_1_the_core.fights)]
for _, v in ipairs(choice) do
add_actor_by_enemy(v)
end
return GAME_STATE_FIGHT
end
})
})

View File

@ -0,0 +1,31 @@
stage_1_the_wasteland = {
fights = { { "RUST_MITE", "RUST_MITE", "RUST_MITE" }, { "SHADOW_ASSASSIN", "SHADOW_ASSASSIN" }, { "SHADOW_ASSASSIN" } }
}
register_story_teller("STAGE_1", {
active = function(ctx)
if had_event("THE_WASTELAND") then
return 1
end
return 0
end,
decide = function(ctx)
local stage = get_stages_cleared()
if stage == 10 then
-- BOSS
end
-- 10% chance to find a random artifact
if math.random() < 0.1 then
set_event(create_artifact_choice({ random_artifact(get_merchant_gold_max()), random_artifact(get_merchant_gold_max()) }))
end
local choice = stage_1_the_wasteland.fights[math.random(#stage_1_the_wasteland.fights)]
for _, v in ipairs(choice) do
add_actor_by_enemy(v)
end
return GAME_STATE_FIGHT
end
})

View File

@ -14,4 +14,4 @@ register_story_teller("STAGE_2", {
return GAME_STATE_FIGHT
end
})
})

View File

@ -1,6 +1,6 @@
#!/bin/bash
for file in ./assets/scripts/*.lua; do
for file in ./assets/scripts/**/*.lua; do
echo "Formatting: $file"
lua-format "$file" -i
done