mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-12 07:54:52 +09:00
Review points from Cooldude: - Feature.register(name[, config]) is required again and returns a feature object. Each feature has its config, its fields, and its overrides, so one registry holds all the data. Only the overrides are stored. On load each feature points at its own stored table again. - The methods are feature:guard(lib), feature:update_config(enabled, values), and feature:is_enabled(). Feature.get(name) looks up a feature, and commands flag the feature object. - update_config raises on_config_updated once per changed value, with the feature name, path, old value, and new value. The gui refresh only reacts to the "enabled" path. - apply only sets values. on_apply is gone. Lookup sets built from lists use Feature.to_set, which is cached by the list itself. A replaced list gets a new set, so the sets are also correct after a load. Protection exposes getters for its protected names and types. Web: settings use small inputs, the same size as the config pages. Fields are shaped like clusterio config field definitions. A field with an inputComponent renders the component registered with the web interface, so the role setting now uses core's role input, and other plugin inputs can be used later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.8 KiB
Lua
54 lines
1.8 KiB
Lua
--[[-- Control - Damage PopUps
|
|
Displays the amount of dmg that is done by players to entities;
|
|
also shows player health when a player is attacked
|
|
]]
|
|
|
|
local FlyingText = require("modules/exp_util/flying_text")
|
|
local Feature = require("modules/exp_scenario/features")
|
|
local feature = require("modules/exp_scenario/config/popups")
|
|
local config = feature.config
|
|
|
|
local random = math.random
|
|
local floor = math.floor
|
|
local max = math.max
|
|
|
|
--- Called when entity entity is damaged including the player character
|
|
--- @param event EventData.on_entity_damaged
|
|
local function on_entity_damaged(event)
|
|
local message
|
|
local cause = event.cause
|
|
local entity = event.entity
|
|
|
|
-- Check which message to display
|
|
if config.show_player_health and entity.name == "character" then
|
|
message = { "exp_damage-popup.flying-text-health", floor(entity.health) }
|
|
elseif config.show_player_damage and entity.name ~= "character" and cause and cause.name == "character" then
|
|
message = { "exp_damage-popup.flying-text-damage", floor(event.original_damage_amount) }
|
|
end
|
|
|
|
-- Outputs the message as floating text
|
|
if message then
|
|
local entity_position = entity.position
|
|
local entity_radius = max(1, entity.get_radius())
|
|
local offset = (random() - 0.5) * entity_radius * config.damage_location_variance
|
|
local position = { x = entity_position.x + offset, y = entity_position.y - entity_radius }
|
|
|
|
local health_percentage = assert(entity.get_health_ratio())
|
|
local color = { r = 1 - health_percentage, g = health_percentage, b = 0 }
|
|
|
|
FlyingText.create{
|
|
text = message,
|
|
position = position,
|
|
color = color,
|
|
}
|
|
end
|
|
end
|
|
|
|
local e = defines.events
|
|
|
|
return feature:guard{
|
|
events = {
|
|
[e.on_entity_damaged] = on_entity_damaged,
|
|
},
|
|
}
|