-- World generation now works for Objects
-- World generation is a lot more leniant
-- World generation now only based on the type of information, not where it is
This commit is contained in:
Hannah-Dagemark 2023-09-19 14:32:17 +02:00
commit 360d26a036
2 changed files with 54 additions and 23 deletions

View file

@ -1,6 +1,6 @@
name=default name=default
size=1920.1080 size=1920.1080
id=001 id=001
statics=house1.100.1080,house2.500.1080 statics=house1.100.1080.100,house2.500.1080.200
interactables= interactables=
objects=bat.1000.1080.50 objects=bat.1000.1080.50,chair.300.1080.35,tree.1400.1080.100

View file

@ -1,57 +1,88 @@
World = { World = {
currentMap = nil, currentMap = nil,
generators = {}
map = {} map = {}
} }
function World.loadMap(name) function World.loadMap(name)
local path = ("maps/"..tostring(name)..".vsmf") local path = ("maps/"..tostring(name)..".vsmf")
--path = ("world.txt") local line_num = 1
for line in love.filesystem.lines(path) do for line in love.filesystem.lines(path) do
line = tostring(line) line = tostring(line)
print ("Itterating line: " .. line) print ("Itterating line: " .. line)
local hasPassedEqual = false local hasPassedEqual = false
local command = "" local command = ""
local args = {""} local args = {}
local i = 1 local B = 1
local A = 1
for character in string.gmatch(line, '.') do for character in string.gmatch(line, '.') do
print ("Itterating character: " .. character) print ("Itterating character: " .. character)
if hasPassedEqual == true then if hasPassedEqual == true then
if character == "." then if character == "." then
i = i + 1 B = B + 1
elseif character == "," then
A = A + 1
B = 1
else else
if args [i] == nil then if args[A] == nil then
args[i] = character args[A] = {}
args[A][B] = tostring(character)
print("Started arg. char. " .. args[A][B])
elseif args[A][B] == nil then
args[A][B] = tostring(character)
print("Started arg. char. " .. args[A][B] .. " (With whole pretext)")
else else
args[i] = args[i] .. character args[A][B] = args[A][B] .. tostring(character)
print ("Argument " .. A .. ":" .. B .. " is now at: " .. args[A][B])
end end
end end
elseif character == "=" then elseif character == "=" then
hasPassedEqual = true hasPassedEqual = true
print ("Passed Equal At: " .. character)
else else
command = command .. character command = command .. character
print ("Command is now at: " .. command)
end
end
if args[A] ~= nil then
for x=1, A do
for y=1, B do
print (command .. ": " .. args[x][y] .. "\n")
end end
end end
print (command .. " " .. args[1] .. "\n")
for x = 1, #args do
if x == 1 then
World.map[command] = {} World.map[command] = {}
World.map[command][args[1]] = {} for x = 1, A do
World.map[command].catalogue = {} World.map[command][x] = {}
table.insert(World.map[command].catalogue, args[1]) print ("Wrote ".. command .. " at " .. x .. " successfully")
print ("Put " .. args[1] .. " in " .. command) for y = 1, B do
else World.map[command][x][y] = args[x][y]
World.map[command][args[1]][x - 1] = args[x] print ("Added " .. args[x][y] .. " to " .. command .. " at " .. x .. ":".. y)
print ("Added " .. args[x] .. " to " .. args[1] .. " at " .. x-1)
end end
end end
end end
end
if World.map.name[1] then
print "Name Success"
end
if World.map.size[1] then
print "Map Success"
end
if World.map.id[1] then
print "ID Success"
end
print("Map has loaded successfully! Loaded with parameters: " .. World.map.name[1][1] .. ", " .. World.map.size[1][1] .. " " .. World.map.size[1][2] .. ", " .. World.map.id[1][1])
print("Attempting hitbox generation...")
if World.map.objects then
World.generators.hitboxes("objects")
end
end end
function World.drawMap() function World.drawMap()
if World.map.objects then if World.map.objects then
for i = 1, #World.map.objects.catalogue do for i=1, #World.map.objects do
love.graphics.circle("line", World.map.objects[World.map.objects.catalogue[i]][1], World.map.objects[World.map.objects.catalogue[i]][2] - World.map.objects[World.map.objects.catalogue[i]][3], World.map.objects[World.map.objects.catalogue[i]][3]) love.graphics.circle("line", World.map.objects[i][2], World.map.objects[i][3] - World.map.objects[i][4], World.map.objects[i][4])
end end
end end
end end