Skip to content

Commit

Permalink
Merge pull request #3 from ChronoVortex/feature/particles
Browse files Browse the repository at this point in the history
added particle system
  • Loading branch information
ChronoVortex authored Jun 26, 2023
2 parents 53843fa + b27a685 commit debd86c
Show file tree
Hide file tree
Showing 10 changed files with 664 additions and 21 deletions.
3 changes: 3 additions & 0 deletions data/hyperspace.xml.append
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
<mod-append:script>data/vertex_module/util.lua</mod-append:script>
<mod-append:script>data/vertex_module/xmlDataInit.lua</mod-append:script>

<mod-append:script>data/vertex_module/particlesInit.lua</mod-append:script>

<mod-append:script>data/vertex_module/tags/augEffects.lua</mod-append:script>
<mod-append:script>data/vertex_module/tags/hack.lua</mod-append:script>
<mod-append:script>data/vertex_module/tags/lockdownBeam.lua</mod-append:script>
<mod-append:script>data/vertex_module/tags/mindControl.lua</mod-append:script>
<mod-append:script>data/vertex_module/tags/noPowerFix.lua</mod-append:script>
<mod-append:script>data/vertex_module/tags/particleEmitters.lua</mod-append:script>
<mod-append:script>data/vertex_module/tags/preignited.lua</mod-append:script>

<mod-append:script>data/vertex_module/xmlDataRead.lua</mod-append:script>
Expand Down
487 changes: 487 additions & 0 deletions data/vertex_module/particlesInit.lua

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions data/vertex_module/tags/augEffects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ local function parser(node)
local augEffects = {}
for augEffectNode in Children(node) do
local augEffect = {}
if not augEffectNode:first_attribute("effect") then error("augEffect tag requires an effect!", 2)
elseif not augEffectNode:first_attribute("amount") then error("augEffect tag requires an amount!", 2)
elseif not tonumber(augEffectNode:first_attribute("amount"):value()) then error("Invalid number for augEffect 'amount' attribute!", 2)
if not augEffectNode:first_attribute("effect") then error("augEffect tag requires an effect!")
elseif not augEffectNode:first_attribute("amount") then error("augEffect tag requires an amount!")
elseif not tonumber(augEffectNode:first_attribute("amount"):value()) then error("Invalid number for augEffect 'amount' attribute!")
end

augEffect.effect = augEffectNode:first_attribute("effect"):value()
Expand Down
6 changes: 3 additions & 3 deletions data/vertex_module/tags/hack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ local crew_data = mods.vertexutil.crew_data
local function parser(node)
local hack = {}

if not node:first_attribute("duration") then error("hack tag requires a duration!", 2) end
if not node:first_attribute("duration") then error("hack tag requires a duration!") end
hack.duration = tonumber(node:first_attribute("duration"):value())
if not hack.duration then error("Invalid number for hack 'duration' attribute!", 2) end
if not hack.duration then error("Invalid number for hack 'duration' attribute!") end

if node:first_attribute("hitShieldDuration") then
hack.hitShieldDuration = tonumber(node:first_attribute("hitShieldDuration"):value())
if not hack.hitShieldDuration then
error("Invalid number for hack 'hitShieldDuration' attribute!", 2)
error("Invalid number for hack 'hitShieldDuration' attribute!")
end
end

Expand Down
6 changes: 3 additions & 3 deletions data/vertex_module/tags/lockdownBeam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ local function parser(node)
if node:first_attribute("chance") then
lockdown.chance = tonumber(node:first_attribute("chance"):value())
if not lockdown.chance then
error("Invalid number for lockdown 'chance' attribute!", 2)
error("Invalid number for lockdown 'chance' attribute!")
end
end

lockdown.sounds = {}
for sound in Children(node) do
if sound:name() ~= "sound" then
error("Invalid child tag '"..sound:name().."' for 'lockdownBeam'!", 2)
error("Invalid child tag '"..sound:name().."' for 'lockdownBeam'!")
end
if not sound:value() then
error("Invalid value for 'sound' child of 'lockdownBeam' tag!", 2)
error("Invalid value for 'sound' child of 'lockdownBeam' tag!")
end
table.insert(lockdown.sounds, sound:value())
end
Expand Down
8 changes: 4 additions & 4 deletions data/vertex_module/tags/mindControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ local function parser(node)

mindControl.duration = node:value()
if not mindControl.duration then
error("mindControl tag requires a value for duration!", 2)
error("mindControl tag requires a value for duration!")
elseif not tonumber(mindControl.duration) then
error("Invalid number for mindControl tag!", 2)
error("Invalid number for mindControl tag!")
end
mindControl.duration = tonumber(mindControl.duration)

if node:first_attribute("limit") then
mindControl.limit = tonumber(node:first_attribute("limit"):value())
if not mindControl.limit then
error("Invalid number for mindControl 'limit' attribute!", 2)
error("Invalid number for mindControl 'limit' attribute!")
end
end

if node:first_attribute("endSound") then
mindControl.endSound = node:first_attribute("endSound"):value()
if not mindControl.endSound then
error("Invalid mindControl 'endSound' attribute!", 2)
error("Invalid mindControl 'endSound' attribute!")
end
end

Expand Down
91 changes: 91 additions & 0 deletions data/vertex_module/tags/particleEmitters.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
-------------
-- IMPORTS --
-------------
local weaponInfo = mods.vertexdata.weaponInfo
local droneInfo = mods.vertexdata.droneInfo
local customTagsAll = mods.vertexdata.customTagsAll
local customTagsWeapons = mods.vertexdata.customTagsWeapons
local customTagsDrones = mods.vertexdata.customTagsDrones
local Children = mods.vertexdata.Children
local parse_xml_bool = mods.vertexdata.parse_xml_bool
local tag_add_all = mods.vertexdata.tag_add_all
local tag_add_weapons = mods.vertexdata.tag_add_weapons
local tag_add_drones = mods.vertexdata.tag_add_drones

local vter = mods.vertexutil.vter
local under_mind_system = mods.vertexutil.under_mind_system
local can_be_mind_controlled = mods.vertexutil.can_be_mind_controlled
local get_ship_crew_point = mods.vertexutil.get_ship_crew_point
local get_adjacent_rooms = mods.vertexutil.get_adjacent_rooms
local get_room_at_location = mods.vertexutil.get_room_at_location
local crew_data = mods.vertexutil.crew_data

local particleLayers = mods.vertexparts.particleLayers
local particles = mods.vertexparts.particles
local particleTypes = mods.vertexparts.particleTypes
local emitterEvents = mods.vertexparts.emitterEvents
local particleEmitters = mods.vertexparts.particleEmitters

------------
-- PARSER --
------------
local function parser(node, weaponName)
for particleEmitterNode in Children(node) do
particleEmitters:ParseNew(particleEmitterNode, weaponName)
end
end

-----------
-- LOGIC --
-----------
local function logic()
-- Render and update particles
script.on_render_event(Defines.RenderEvents.SHIP, function(ship)
particles:Render(ship.iShipId, particleLayers.BOTTOM)
end, function(ship)
particles:Render(ship.iShipId, particleLayers.TOP)
end)
script.on_internal_event(Defines.InternalEvents.ON_TICK, function(ship)
if not Hyperspace.Global.GetInstance():GetCApp().world.space.gamePaused then
particles:Update()
end
end)

-- Emitter fire event
script.on_internal_event(Defines.InternalEvents.PROJECTILE_FIRE, function(projectile, weapon)
if weapon then
local weaponEmitters = particleEmitters.activeEmitters[weapon.blueprint.name]
if weaponEmitters then
for i, emitter in ipairs(weaponEmitters) do
particleEmitters:Emit(emitter, emitterEvents.FIRE, weapon)
end
end
end
end)

-- Emitter explosion event
local function emitter_explosion(projectile)
if projectile then
local weaponEmitters = particleEmitters.activeEmitters[projectile.extend.name]
if weaponEmitters then
for i, emitter in ipairs(weaponEmitters) do
particleEmitters:Emit(emitter, emitterEvents.EXPLOSION, nil, projectile.position.x, projectile.position.y, projectile.currentSpace)
end
end
end
end
script.on_internal_event(Defines.InternalEvents.DRONE_COLLISION, function(drone, projectile, damage, response)
emitter_explosion(projectile)
end)
script.on_internal_event(Defines.InternalEvents.PROJECTILE_COLLISION, function(thisProjectile, otherProjectile, damage, response)
emitter_explosion(thisProjectile)
end)
script.on_internal_event(Defines.InternalEvents.SHIELD_COLLISION, function(ship, projectile, damage, response)
emitter_explosion(projectile)
end)
script.on_internal_event(Defines.InternalEvents.DAMAGE_AREA_HIT, function(ship, projectile, damage, response)
emitter_explosion(projectile)
end)
end

tag_add_weapons("particleEmitters", parser, logic)
68 changes: 65 additions & 3 deletions data/vertex_module/util.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if not (Hyperspace.version and Hyperspace.version.major == 1 and Hyperspace.version.minor >= 3) then
error("Incorrect Hyperspace version detected! Vertex Tags and Utility Functions requires Hyperspace 1.3+")
if not (Hyperspace.version and Hyperspace.version.major == 1 and Hyperspace.version.minor >= 4) then
error("Incorrect Hyperspace version detected! Vertex Tags and Utility Functions requires Hyperspace 1.4+")
end

mods.vertexutil = {}
Expand All @@ -10,7 +10,7 @@ local INT_MAX = 2147483647
----------------------------
-- Generic iterator for C vectors
function mods.vertexutil.vter(cvec)
local i = -1 --so the first returned value is indexed at zero
local i = -1 -- so the first returned value is indexed at zero
local n = cvec:size()
return function()
i = i + 1
Expand All @@ -19,6 +19,68 @@ function mods.vertexutil.vter(cvec)
end
local vter = mods.vertexutil.vter

-- Copy a table recursively
--[[ taken from
https://stackoverflow.com/questions/42178768/lua-copying-a-table-efficiently-deep-copy#answer-45867020
https://gist.github.com/cpeosphoros/0aa286c6b39c1e452d9aa15d7537ac95
--]]
function mods.vertexutil.table_copy_deep(value, cache, promises, copies)
cache = cache or {}
promises = promises or {}
copies = copies or {}
local copy
if type(value) == 'table' then
if (cache[value]) then
copy = cache[value]
else
promises[value] = promises[value] or {}
copy = {}
for k, v in next, value, nil do
local nKey = promises[k] or mods.vertexutil.table_copy_deep(k, cache, promises, copies)
local nValue = promises[v] or mods.vertexutil.table_copy_deep(v, cache, promises, copies)
copies[nKey] = type(k) == "table" and k or nil
copies[nValue] = type(v) == "table" and v or nil
copy[nKey] = nValue
end
local mt = getmetatable(value)
if mt then
setmetatable(copy, mt.__immutable and mt or mods.vertexutil.table_copy_deep(mt, cache, promises, copies))
end
cache[value] = copy
end
else -- number, string, boolean, etc
copy = value
end
for k, v in pairs(copies) do
if k == cache[v] then
copies[k] = nil
end
end
local function correctRec(tbl)
if type(tbl) ~= "table" then return tbl end
if copies[tbl] and cache[copies[tbl]] then
return cache[copies[tbl]]
end
local new = {}
for k, v in pairs(tbl) do
local oldK = k
k, v = correctRec(k), correctRec(v)
if k ~= oldK then
tbl[oldK] = nil
new[k] = v
else
tbl[k] = v
end
end
for k, v in pairs(new) do
tbl[k] = v
end
return tbl
end
correctRec(copy)
return copy
end

-- Check if a given crew member is being mind controlled by a ship system
function mods.vertexutil.under_mind_system(crewmem)
local controlledCrew = nil
Expand Down
8 changes: 4 additions & 4 deletions data/vertex_module/xmlDataRead.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for _, file in ipairs(blueprintFiles) do
customTagsAll[tag].hooked = true
end
log("Found "..tag.." tag for weapon "..thisWeaponName)
thisWeaponInfo[tag] = customTagsAll[tag].parser(wepNode)
thisWeaponInfo[tag] = customTagsAll[tag].parser(wepNode, thisWeaponName)
end
if customTagsWeapons[tag] then
if not customTagsWeapons[tag].hooked then
Expand All @@ -37,7 +37,7 @@ for _, file in ipairs(blueprintFiles) do
customTagsWeapons[tag].hooked = true
end
log("Found "..tag.." tag for weapon "..thisWeaponName)
thisWeaponInfo[tag] = customTagsWeapons[tag].parser(wepNode)
thisWeaponInfo[tag] = customTagsWeapons[tag].parser(wepNode, thisWeaponName)
end
end
for tag in pairs(customTagsAll) do
Expand All @@ -63,7 +63,7 @@ for _, file in ipairs(blueprintFiles) do
customTagsAll[tag].hooked = true
end
log("Found "..tag.." tag for drone "..thisDroneName)
thisDroneInfo[tag] = customTagsAll[tag].parser(droneNode)
thisDroneInfo[tag] = customTagsAll[tag].parser(droneNode, thisDroneName)
end
if customTagsDrones[tag] then
if not customTagsDrones[tag].hooked then
Expand All @@ -72,7 +72,7 @@ for _, file in ipairs(blueprintFiles) do
customTagsDrones[tag].hooked = true
end
log("Found "..tag.." tag for drone "..thisDroneName)
thisDroneInfo[tag] = customTagsDrones[tag].parser(droneNode)
thisDroneInfo[tag] = customTagsDrones[tag].parser(droneNode, thisDroneName)
end
end
for tag in pairs(customTagsAll) do
Expand Down
2 changes: 1 addition & 1 deletion mod-appendix/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<title><![CDATA[ Vertex Tags and Utility Functions ]]></title>
<threadUrl><![CDATA[ https://github.com/ChronoVortex/FTL-HS-Vertex ]]></threadUrl>
<author><![CDATA[ Vertaalfout, Chrono Vortex ]]></author>
<version><![CDATA[ 2.1 ]]></version>
<version><![CDATA[ 3.0 ]]></version>
<description>
<![CDATA[
This mod has no content, instead adding new tags and LUA utility functions for other mods to build off of.
Expand Down

0 comments on commit debd86c

Please sign in to comment.