Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RGBProductions committed Aug 15, 2022
1 parent e710886 commit 20c72e2
Show file tree
Hide file tree
Showing 11 changed files with 883 additions and 96 deletions.
Binary file added assets/images/ui/logo-updated.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion assets/text/credits.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[
{"type": "header", "label": "Programmer / Graphics"},
{"type": "header", "label": "Programming"},
{"type": "name", "label": "Lead Programmer - RGB Productions"},
{"type": "name", "label": "Update Checker - MichaelEpicA"},

{"type": "header", "label": "Graphics"},
{"type": "name", "label": "RGB Productions"},

{"type": "header", "label": "Music"},
Expand Down
28 changes: 27 additions & 1 deletion game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,36 @@ function Game.Die:newRoll()
end

function Game.Die:update(dt)
local die = GetPoolByID(Settings["Gameplay"]["Dice Weighing Mode"]).Die
if Settings["Gameplay"]["Dice Weighing Mode"] == 2 then
local Stats = player:get("stats")
die = {}
-- Calculate Total Statistic Score
local statscore = (Stats["Attack"]/150)*0.4 + (Stats["Defense"]/150)*0.4 + (Stats["Luck"]/90)*0.2
local istatscore = 1-statscore
for n = 1, istatscore*8 do
table.insert(die, 6)
end
for n = 1, istatscore*6 do
table.insert(die, 5)
end
for n = 1, istatscore*4 do
table.insert(die, 4)
end
for n = 1, statscore*8 do
table.insert(die, 1)
end
for n = 1, statscore*6 do
table.insert(die, 2)
end
for n = 1, statscore*4 do
table.insert(die, 3)
end
end
if not self.doneRolling then
self.time = self.time + dt
if self.time >= 0.125 then
self.number = love.math.random(1,6)
self.number = die[love.math.random(1,#die)]
self.rollIter = self.rollIter + 1
self.time = 0
end
Expand Down
176 changes: 171 additions & 5 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,121 @@
love.filesystem.write("https.so", love.filesystem.read("https.so"))
love.filesystem.write("https.dll", love.filesystem.read("https.dll"))
local https = require "https"
require "scenemanager"
require "pools"

json = require "json"
love.graphics.setDefaultFilter("nearest", "nearest")

function string.split(text, delimiter)
local result = {}
for match in (text..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end

function string.split_plain(text, delimiter)
local result = {}
local current = ""
for i = 1, #text do
if text:sub(i,i) == delimiter then
table.insert(result, current)
current = ""
else
current = current .. text:sub(i,i)
end
end
table.insert(result, current)
return result
end

function table.join(t, s)
s = s or ", "
local res = ""
for n,i in ipairs(t) do
res = res .. i
if n ~= #t then
res = res .. s
end
end
return res
end

function RecursiveDelete( item )
if love.filesystem.getInfo( item , "directory" ) then
for _, child in pairs( love.filesystem.getDirectoryItems( item )) do
RecursiveDelete( item .. '/' .. child )
love.filesystem.remove( item .. '/' .. child )
end
elseif love.filesystem.getInfo( item ) then
love.filesystem.remove( item )
end
love.filesystem.remove( item )
end

local curver = love.filesystem.read("version.txt"):split("\n")
version = curver[1]
version_number = curver[2]
update = {false, version}
beta = false
--how do you feel rn--
-- local vals = string.split_plain("1.0-JAM", ".")
-- local t = string.split_plain(vals[#vals], "-")
-- for i,v in ipairs(vals) do
-- vals[i] = string.split_plain(v, "-")[1]
-- end
-- print("Major: " .. vals[1])
-- print("Minor: " .. vals[2])
-- print("Revision: " .. (vals[3] or 0))
-- print("Type: " .. (t[2] or "RELEASE"))
-- print("Full version: " .. vals[1] .. "." .. vals[2] .. "." .. (vals[3] or 0) .. "-" .. (t[2] or "RELEASE"))
-- print("Actual version: " .. table.join(vals, "."))

function CompareVersions(a,b)
local t1 = string.split_plain(a, ".")
local t2 = string.split_plain(b, ".")
for i,v in ipairs(t1) do
t1[i] = string.split_plain(v, "-")[1]
end
for i,v in ipairs(t2) do
t2[i] = string.split_plain(v, "-")[1]
end

for i = 1, math.max(#t1,#t2) do
if tonumber(t1[i] or 0) > tonumber(t2[i] or 0) then
return 1
end
if tonumber(t1[i] or 0) < tonumber(t2[i] or 0) then
return -1
end
end
return 0
end

UpdateCheckFailed = 0

-- MichaelEpicA's Method
function CheckForUpdates()
-- local code,data,headers,unknown = https.request("https://github.com/TheFuryBumblebee/TheSlashOfTheDice/releases/latest")
local code,data,headers = https.request("https://github.com/TheFuryBumblebee/TheSlashOfTheDice/releases/latest", {method = "get"})
local location = headers.location
if not headers.location then
location = headers.Location -- Windows
end
local real_url = location:sub(2,-1)
local spl = real_url:split("/")
local tag = spl[#spl]
local cmp = CompareVersions(version, tag:sub(2,-1))
if cmp == 1 then
beta = true
elseif cmp == -1 then
update = {true, tag}
end
end

CheckForUpdates()

function table.index(t,v)
for n,i in pairs(t) do
if i == v then
Expand All @@ -16,14 +129,18 @@ function math.round(x)
return math.floor(x+0.5)
end

function math.sign(x)
return (x > 0 and 1) or (x < 0 and -1) or 0
end

function LoadMusic(fn)
local s,r = pcall(love.audio.newSource, fn, "stream")
if not s then
return print("WARNING: Music " .. fn .. " not found; skipping")
end
Music = r
Music:setLooping(true)
Music:setVolume(Settings["Music Volume"]/100)
Music:setVolume(Settings["Audio"]["Music Volume"]/100)
Music:play()
end

Expand All @@ -33,14 +150,63 @@ function StopMusic()
end
end

function deepcopy(orig, copies)
copies = copies or {}
local orig_type = type(orig)
local copy
if orig_type == 'table' then
if copies[orig] then
copy = copies[orig]
else
copy = {}
copies[orig] = copy
for orig_key, orig_value in next, orig, nil do
copy[deepcopy(orig_key, copies)] = deepcopy(orig_value, copies)
end
setmetatable(copy, deepcopy(getmetatable(orig), copies))
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end

function RecursiveOverwrite(t1, t2)
for k,v in pairs(t2) do
if type(v) == "table" then
t1[k] = {}
t1[k] = RecursiveOverwrite(t1[k], v)
else
t1[k] = v
end
end
return t1
end

function table.merge(t, m)
local res = deepcopy(t)
return RecursiveOverwrite(res, m)
end

function love.load()
Settings = {
["UI Scale"] = 1.5,
["Sound Volume"] = 75,
["Music Volume"] = 75
["Video"] = {
["UI Scale"] = 1.5,
["Color by Operator"] = true
},

["Audio"] = {
["Sound Volume"] = 75,
["Music Volume"] = 75
},

["Gameplay"] = {
["Dice Weighing Mode"] = 2
}
}
if love.filesystem.getInfo("settings.json") then
Settings = json.decode(love.filesystem.read("settings.json"))
local itms = json.decode(love.filesystem.read("settings.json"))
Settings = table.merge(Settings, itms)
end
SceneManager.LoadScene("scenes/menu", {})
end
Expand Down
33 changes: 33 additions & 0 deletions pools.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- Used for all dice weighing modes except Situational, which needs special code
Pools = {
-- The way dice were handled in the jam version
Legacy = {
Operators = {"add","add","add","add", "mul","mul","mul", "sub", "div"},
Die = {1,2,3,4,5,6}
},
-- All outcomes are equally likely
Even = {
Operators = {"add","mul","sub","div"},
Die = {1,2,3,4,5,6}
},
-- Negative outcomes are more common
Unfair = {
Operators = {"sub","sub","sub","sub", "div","div","div", "add", "mul"},
Die = {1,1,1,1,1,2,2,2,2,3,3,3,3,4,5,6}
}
}

function GetPoolByID(id)
if id == 0 then
return Pools.Legacy
end
if id == 1 then
return Pools.Even
end
if id == 2 then
return Pools.Legacy -- Placeholder: Real pools are dynamically generated
end
if id == 3 then
return Pools.Unfair -- pain
end
end
8 changes: 4 additions & 4 deletions scenes/credits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ end
function scene.draw()
love.graphics.setColor(1,1,1)
love.graphics.setFont(xlfont)
love.graphics.printf("Credits", 0, LogoPos + Logo:getHeight()*Settings["UI Scale"] + xlfont:getHeight() - CreditScroll, love.graphics.getWidth(), "center")
love.graphics.printf("Credits", 0, LogoPos + Logo:getHeight()*Settings["Video"]["UI Scale"] + xlfont:getHeight() - CreditScroll, love.graphics.getWidth(), "center")

local pos = 0
local lastType = "header"
for i = 1, #Credits do
if Credits[i]["type"] == "header" and lastType == "name" then
pos = pos + xlfont:getHeight()
pos = pos + lrfont:getHeight()
end
love.graphics.setFont(xlfont)
if Credits[i]["type"] == "name" then
love.graphics.setFont(lrfont)
end
love.graphics.printf(Credits[i]["label"], 0, LogoPos + Logo:getHeight()*Settings["UI Scale"] + xlfont:getHeight()*3 + pos - CreditScroll, love.graphics.getWidth(), "center")
love.graphics.printf(Credits[i]["label"], 0, LogoPos + Logo:getHeight()*Settings["Video"]["UI Scale"] + xlfont:getHeight()*3 + pos - CreditScroll, love.graphics.getWidth(), "center")
pos = pos + love.graphics.getFont():getHeight()
lastType = Credits[i]["type"]
end

love.graphics.draw(Logo, love.graphics.getWidth()/2, LogoPos, 0, Settings["UI Scale"], Settings["UI Scale"], Logo:getWidth()/2, 0)
love.graphics.draw(Logo, love.graphics.getWidth()/2, LogoPos, 0, Settings["Video"]["UI Scale"], Settings["Video"]["UI Scale"], Logo:getWidth()/2, 0)
end

function scene.wheelmoved(x, y)
Expand Down

0 comments on commit 20c72e2

Please sign in to comment.