<commit_before>local Class = require 'lib.hump.class'
local vector = require 'lib.hump.vector'

-- map classes
local Map = getClass 'pud.map.Map'
local MapDirector = getClass 'pud.map.MapDirector'
local FileMapBuilder = getClass 'pud.map.FileMapBuilder'
local SimpleGridMapBuilder = getClass 'pud.map.SimpleGridMapBuilder'
local MapNode = getClass 'pud.map.MapNode'
local DoorMapType = getClass 'pud.map.DoorMapType'

-- events
local MapUpdateFinishedEvent = getClass 'pud.event.MapUpdateFinishedEvent'
local MapNodeUpdateEvent = getClass 'pud.event.MapNodeUpdateEvent'
local ZoneTriggerEvent = getClass 'pud.event.ZoneTriggerEvent'
local EntityPositionEvent = getClass 'pud.event.EntityPositionEvent'

-- entities
local HeroFactory = getClass 'pud.entity.HeroFactory'
local EnemyFactory = getClass 'pud.entity.EnemyFactory'
local ItemFactory = getClass 'pud.entity.ItemFactory'
local message = getClass 'pud.component.message'
local property = require 'pud.component.property'

local math_floor = math.floor
local math_round = function(x) return math_floor(x+0.5) end

-- Level
--
local Level = Class{name='Level',
	function(self)
		self._heroFactory = HeroFactory()
		self._enemyFactory = EnemyFactory()
		self._itemFactory = ItemFactory()

		-- lighting color value table
		self._lightColor = {
			black = {0,0,0},
			dim = {0.4, 0.4, 0.4},
			lit = {1,1,1},
		}
		self._lightmap = {}
		self._entities = {}

		GameEvents:register(self, {EntityPositionEvent, MapNodeUpdateEvent})
	end
}

-- destructor
function Level:destroy()
	GameEvents:unregisterAll(self)
	self._map:destroy()
	self._map = nil
	self._heroFactory:destroy()
	self._heroFactory = nil
	self._enemyFactory:destroy()
	self._enemyFactory = nil
	self._itemFactory:destroy()
	self._itemFactory = nil
	for k in pairs(self._entities) do
		self._entities[k]:destroy()
		self._entities[k] = nil
	end
	self._entities = nil
	for k in pairs(self._lightColor) do self._lightColor[k] = nil end
	self._lightColor = nil
	for k in pairs(self._lightmap) do self._lightmap[k] = nil end
	self._lightmap = nil
end

function Level:_triggerZones(entity, pos, oldpos)
	if pos ~= oldpos then
		local zonesFrom = self._map:getZonesFromPoint(oldpos)
		local zonesTo = self._map:getZonesFromPoint(pos)

		if zonesFrom then
			for zone in pairs(zonesFrom) do
				if zonesTo and zonesTo[zone] then
					zonesTo[zone] = nil
				else
					GameEvents:push(ZoneTriggerEvent(entity, zone, true))
				end
			end
		end

		if zonesTo then
			for zone in pairs(zonesTo) do
				GameEvents:push(ZoneTriggerEvent(entity, zone, false))
			end
		end
	end
end

function Level:needViewUpdate() return self._needViewUpdate == true end
function Level:postViewUpdate() self._needViewUpdate = false end

function Level:generateFileMap(file)
	local maps = love.filesystem.enumerate('map')
	file = file or maps[Random(#maps)]
	local builder = FileMapBuilder('map/'..file)
	self:_generateMap(builder)
end

function Level:generateSimpleGridMap()
	local builder = SimpleGridMapBuilder(80,80, 10,10, 8,16)
	self:_generateMap(builder)
end

function Level:_generateMap(builder)
	if self._map then self._map:destroy() end
	self._map = MapDirector:generateStandard(builder)<commit_msg>localize love.filesystem.enumerate<commit_after>local Class = require 'lib.hump.class'
local vector = require 'lib.hump.vector'

-- map classes
local Map = getClass 'pud.map.Map'
local MapDirector = getClass 'pud.map.MapDirector'
local FileMapBuilder = getClass 'pud.map.FileMapBuilder'
local SimpleGridMapBuilder = getClass 'pud.map.SimpleGridMapBuilder'
local MapNode = getClass 'pud.map.MapNode'
local DoorMapType = getClass 'pud.map.DoorMapType'

-- events
local MapUpdateFinishedEvent = getClass 'pud.event.MapUpdateFinishedEvent'
local MapNodeUpdateEvent = getClass 'pud.event.MapNodeUpdateEvent'
local ZoneTriggerEvent = getClass 'pud.event.ZoneTriggerEvent'
local EntityPositionEvent = getClass 'pud.event.EntityPositionEvent'

-- entities
local HeroFactory = getClass 'pud.entity.HeroFactory'
local EnemyFactory = getClass 'pud.entity.EnemyFactory'
local ItemFactory = getClass 'pud.entity.ItemFactory'
local message = getClass 'pud.component.message'
local property = require 'pud.component.property'

local math_floor = math.floor
local math_round = function(x) return math_floor(x+0.5) end
local enumerate = love.filesystem.enumerate

-- Level
--
local Level = Class{name='Level',
	function(self)
		self._heroFactory = HeroFactory()
		self._enemyFactory = EnemyFactory()
		self._itemFactory = ItemFactory()

		-- lighting color value table
		self._lightColor = {
			black = {0,0,0},
			dim = {0.4, 0.4, 0.4},
			lit = {1,1,1},
		}
		self._lightmap = {}
		self._entities = {}

		GameEvents:register(self, {EntityPositionEvent, MapNodeUpdateEvent})
	end
}

-- destructor
function Level:destroy()
	GameEvents:unregisterAll(self)
	self._map:destroy()
	self._map = nil
	self._heroFactory:destroy()
	self._heroFactory = nil
	self._enemyFactory:destroy()
	self._enemyFactory = nil
	self._itemFactory:destroy()
	self._itemFactory = nil
	for k in pairs(self._entities) do
		self._entities[k]:destroy()
		self._entities[k] = nil
	end
	self._entities = nil
	for k in pairs(self._lightColor) do self._lightColor[k] = nil end
	self._lightColor = nil
	for k in pairs(self._lightmap) do self._lightmap[k] = nil end
	self._lightmap = nil
end

function Level:_triggerZones(entity, pos, oldpos)
	if pos ~= oldpos then
		local zonesFrom = self._map:getZonesFromPoint(oldpos)
		local zonesTo = self._map:getZonesFromPoint(pos)

		if zonesFrom then
			for zone in pairs(zonesFrom) do
				if zonesTo and zonesTo[zone] then
					zonesTo[zone] = nil
				else
					GameEvents:push(ZoneTriggerEvent(entity, zone, true))
				end
			end
		end

		if zonesTo then
			for zone in pairs(zonesTo) do
				GameEvents:push(ZoneTriggerEvent(entity, zone, false))
			end
		end
	end
end

function Level:needViewUpdate() return self._needViewUpdate == true end
function Level:postViewUpdate() self._needViewUpdate = false end

function Level:generateFileMap(file)
	local maps = enumerate('map')
	file = file or maps[Random(#maps)]
	local builder = FileMapBuilder('map/'..file)
	self:_generateMap(builder)
end

function Level:generateSimpleGridMap()
	local builder = SimpleGridMapBuilder(80,80, 10,10, 8,16)
	self:_generateMap(builder)
end

function Level:_generateMap(builder)
	if self._map then self._map:destroy() end
	self._map = MapDirector:generateStandard(builder)
{'fraction_non_alphanumeric': 0.10613830613830613, 'fraction_numerical': 0.00777000777000777, 'mean_word_length': 5.060263653483992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2082448', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2098, 'n_words': 509}