mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Merge Game, FlyingText, Common and table
This commit is contained in:
89
exp_util/module/flying_text.lua
Normal file
89
exp_util/module/flying_text.lua
Normal file
@@ -0,0 +1,89 @@
|
||||
--[[-- Util Module - FlyingText
|
||||
Provides a method of creating floating text and tags in the world
|
||||
]]
|
||||
|
||||
local FlyingText = {}
|
||||
FlyingText.color = require("modules/exp_util/include/color")
|
||||
|
||||
--- @class FlyingText.create_param:LuaPlayer.create_local_flying_text_param
|
||||
--- @field player? LuaPlayer The player to create the text for
|
||||
--- @field surface? LuaSurface The surface to create the text for
|
||||
--- @field force? LuaForce The force to create the text for
|
||||
|
||||
--- Create flying text for a player, force, or surface; default is all online players
|
||||
--- @param options FlyingText.create_param
|
||||
function FlyingText.create(options)
|
||||
if options.player then
|
||||
options.player.create_local_flying_text(options)
|
||||
elseif options.force then
|
||||
for _, player in pairs(options.force.connected_players) do
|
||||
player.create_local_flying_text(options)
|
||||
end
|
||||
elseif options.surface then
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.surface == options.surface then
|
||||
player.create_local_flying_text(options)
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, player in pairs(game.connected_players) do
|
||||
player.create_local_flying_text(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- @class FlyingText.create_above_entity_param:FlyingText.create_param
|
||||
--- @field target_entity? LuaEntity The entity to create the text above
|
||||
|
||||
--- Create flying above an entity, overrides the position option of FlyingText.create
|
||||
--- @param options FlyingText.create_above_entity_param
|
||||
function FlyingText.create_above_entity(options)
|
||||
local entity = assert(options.target_entity, "A target entity is required")
|
||||
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
||||
|
||||
options.position = {
|
||||
x = entity.position.x,
|
||||
y = entity.position.y - size_y * 0.25,
|
||||
}
|
||||
|
||||
FlyingText.create(options)
|
||||
end
|
||||
|
||||
--- @class FlyingText.create_above_player_param:FlyingText.create_param
|
||||
--- @field target_player? LuaPlayer The player to create the text above
|
||||
|
||||
--- Create flying above a player, overrides the position option of FlyingText.create
|
||||
--- @param options FlyingText.create_above_player_param
|
||||
function FlyingText.create_above_player(options)
|
||||
local player = assert(options.target_player, "A target entity is required")
|
||||
local entity = player.character; if not entity then return end
|
||||
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
||||
|
||||
options.position = {
|
||||
x = entity.position.x,
|
||||
y = entity.position.y - size_y * 0.25,
|
||||
}
|
||||
|
||||
FlyingText.create(options)
|
||||
end
|
||||
|
||||
--- @class FlyingText.create_as_player_param:FlyingText.create_param
|
||||
--- @field target_player? LuaPlayer The player to create the text above
|
||||
|
||||
--- Create flying above a player, overrides the position and color option of FlyingText.create
|
||||
--- @param options FlyingText.create_as_player_param
|
||||
function FlyingText.create_as_player(options)
|
||||
local player = assert(options.target_player, "A target entity is required")
|
||||
local entity = player.character; if not entity then return end
|
||||
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
||||
|
||||
options.color = player.chat_color
|
||||
options.position = {
|
||||
x = entity.position.x,
|
||||
y = entity.position.y - size_y * 0.25,
|
||||
}
|
||||
|
||||
FlyingText.create(options)
|
||||
end
|
||||
|
||||
return FlyingText
|
||||
Reference in New Issue
Block a user