mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-30 23:17:53 +02:00
minor changes
This commit is contained in:
parent
5f6a3df0b9
commit
04a9abb2f7
@ -1,10 +1,13 @@
|
||||
--antigrief things made by mewmew
|
||||
|
||||
local event = require 'utils.event'
|
||||
local Event = require 'utils.event'
|
||||
local Jailed = require 'utils.jail_data'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
local AntiGrief = require 'antigrief'
|
||||
|
||||
local lower = string.lower
|
||||
local gmatch = string.gmatch
|
||||
|
||||
local function admin_only_message(str)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.admin == true then
|
||||
@ -193,6 +196,109 @@ local function create_mini_camera_gui(player, caption, position, surface)
|
||||
camera.style.minimal_height = 480
|
||||
end
|
||||
|
||||
local function filter_brackets(str)
|
||||
return (string.find(str, '%[') ~= nil)
|
||||
end
|
||||
|
||||
local function match_test(value, pattern)
|
||||
return lower(value:gsub('-', ' ')):find(pattern)
|
||||
end
|
||||
|
||||
local function draw_events(data)
|
||||
local frame = data.frame
|
||||
local antigrief = data.antigrief
|
||||
local search_text = data.search_text or nil
|
||||
local history = frame['admin_history_select'].items[frame['admin_history_select'].selected_index]
|
||||
|
||||
local history_index = {
|
||||
['Capsule History'] = antigrief.capsule_history,
|
||||
['Friendly Fire History'] = antigrief.friendly_fire_history,
|
||||
['Mining History'] = antigrief.mining_history,
|
||||
['Landfill History'] = antigrief.landfill_history,
|
||||
['Corpse Looting History'] = antigrief.corpse_history
|
||||
}
|
||||
|
||||
local scroll_pane
|
||||
if frame.datalog then
|
||||
frame.datalog.clear()
|
||||
else
|
||||
scroll_pane =
|
||||
frame.add(
|
||||
{
|
||||
type = 'scroll-pane',
|
||||
name = 'datalog',
|
||||
direction = 'vertical',
|
||||
horizontal_scroll_policy = 'never',
|
||||
vertical_scroll_policy = 'auto'
|
||||
}
|
||||
)
|
||||
scroll_pane.style.maximal_height = 200
|
||||
end
|
||||
|
||||
local target_player_name = frame['admin_player_select'].items[frame['admin_player_select'].selected_index]
|
||||
|
||||
local finder
|
||||
|
||||
if game.players[target_player_name] then
|
||||
local target_player = game.players[target_player_name].index
|
||||
finder = target_player
|
||||
end
|
||||
for key, value in pairs(history_index[history]) do
|
||||
if not finder then
|
||||
finder = key
|
||||
end
|
||||
if key == finder then
|
||||
for i = #value, 1, -1 do
|
||||
if search_text then
|
||||
if filter_brackets(search_text) then
|
||||
goto continue
|
||||
end
|
||||
if not match_test(value[i], search_text) then
|
||||
goto continue
|
||||
end
|
||||
end
|
||||
frame.datalog.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = history_index[history][finder][i],
|
||||
tooltip = 'Click to open mini camera.'
|
||||
}
|
||||
)
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function text_changed(event)
|
||||
local element = event.element
|
||||
if not element then
|
||||
return
|
||||
end
|
||||
if not element.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local antigrief = AntiGrief.get()
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local frame = Tabs.comfy_panel_get_active_frame(player)
|
||||
if not frame then
|
||||
return
|
||||
end
|
||||
if frame.name ~= 'Admin' then
|
||||
return
|
||||
end
|
||||
|
||||
local data = {
|
||||
frame = frame,
|
||||
antigrief = antigrief,
|
||||
search_text = element.text
|
||||
}
|
||||
|
||||
draw_events(data)
|
||||
end
|
||||
|
||||
local create_admin_panel = (function(player, frame)
|
||||
local antigrief = AntiGrief.get()
|
||||
frame.clear()
|
||||
@ -344,7 +450,14 @@ local create_admin_panel = (function(player, frame)
|
||||
return
|
||||
end
|
||||
|
||||
local search_table = frame.add({type = 'table', column_count = 2})
|
||||
search_table.add({type = 'label', caption = 'Search: '})
|
||||
local search_text = search_table.add({type = 'textfield'})
|
||||
search_text.style.width = 140
|
||||
|
||||
local l = frame.add({type = 'label', caption = '----------------------------------------------'})
|
||||
l.style.font = 'default-listbox'
|
||||
l.style.font_color = {r = 0.98, g = 0.66, b = 0.22}
|
||||
|
||||
local selected_index_2 = 1
|
||||
if global.admin_panel_selected_history_index then
|
||||
@ -360,62 +473,12 @@ local create_admin_panel = (function(player, frame)
|
||||
drop_down_2.style.right_padding = 12
|
||||
drop_down_2.style.left_padding = 12
|
||||
|
||||
local history = frame['admin_history_select'].items[frame['admin_history_select'].selected_index]
|
||||
|
||||
local history_index = {
|
||||
['Capsule History'] = antigrief.capsule_history,
|
||||
['Friendly Fire History'] = antigrief.friendly_fire_history,
|
||||
['Mining History'] = antigrief.mining_history,
|
||||
['Landfill History'] = antigrief.landfill_history,
|
||||
['Corpse Looting History'] = antigrief.corpse_history
|
||||
local data = {
|
||||
frame = frame,
|
||||
antigrief = antigrief
|
||||
}
|
||||
|
||||
local t = frame.add({type = 'table', column_count = 1})
|
||||
l.style.font = 'default-listbox'
|
||||
l.style.font_color = {r = 0.98, g = 0.66, b = 0.22}
|
||||
local scroll_pane =
|
||||
t.add(
|
||||
{
|
||||
type = 'scroll-pane',
|
||||
direction = 'vertical',
|
||||
horizontal_scroll_policy = 'never',
|
||||
vertical_scroll_policy = 'auto'
|
||||
}
|
||||
)
|
||||
scroll_pane.style.maximal_height = 200
|
||||
|
||||
local target_player_name = frame['admin_player_select'].items[frame['admin_player_select'].selected_index]
|
||||
|
||||
if game.players[target_player_name] then
|
||||
for k, v in pairs(history_index[history]) do
|
||||
local target_player = game.players[target_player_name].index
|
||||
if k == target_player then
|
||||
for i = #v, 1, -1 do
|
||||
scroll_pane.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = history_index[history][target_player][i],
|
||||
tooltip = 'Click to open mini camera.'
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for k, v in pairs(history_index[history]) do
|
||||
if history_index[history][k] ~= nil and history_index[history][k] ~= '' then
|
||||
for i = #v, 1, -1 do
|
||||
scroll_pane.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = history_index[history][k][i],
|
||||
tooltip = 'Click to open mini camera.'
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
draw_events(data)
|
||||
end)
|
||||
|
||||
local admin_functions = {
|
||||
@ -613,5 +676,6 @@ end
|
||||
|
||||
comfy_panel_tabs['Admin'] = {gui = create_admin_panel, admin = true}
|
||||
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed)
|
||||
Event.add(defines.events.on_gui_text_changed, text_changed)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed)
|
||||
|
@ -253,7 +253,7 @@ local function close_market_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function redraw_market_items(gui, player)
|
||||
local function redraw_market_items(gui, player, search_text)
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
@ -268,6 +268,15 @@ local function redraw_market_items(gui, player)
|
||||
|
||||
local slider_value = math.ceil(this.players[player.index].data.slider.slider_value)
|
||||
for item, data in pairs(Public.get_items()) do
|
||||
if not search_text then
|
||||
goto continue
|
||||
end
|
||||
if not search_text.text then
|
||||
goto continue
|
||||
end
|
||||
if not string.lower(item:gsub('-', ' ')):find(search_text.text) then
|
||||
goto continue
|
||||
end
|
||||
local item_count = data.stack * slider_value
|
||||
local item_cost = data.price * slider_value
|
||||
|
||||
@ -298,6 +307,7 @@ local function redraw_market_items(gui, player)
|
||||
if player_item_count < item_cost then
|
||||
button.enabled = false
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
@ -344,10 +354,18 @@ local function slider_changed(event)
|
||||
end
|
||||
slider_value = math.ceil(slider_value)
|
||||
this.players[player.index].data.text_input.text = slider_value
|
||||
redraw_market_items(this.players[player.index].data.item_frame, player)
|
||||
redraw_market_items(this.players[player.index].data.item_frame, player, this.players[player.index].data.search_text)
|
||||
end
|
||||
|
||||
local function text_changed(event)
|
||||
local element = event.element
|
||||
if not element then
|
||||
return
|
||||
end
|
||||
if not element.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local this = WPT.get()
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
@ -369,9 +387,7 @@ local function text_changed(event)
|
||||
return
|
||||
end
|
||||
|
||||
this.players[player.index].data.slider.slider_value = value
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
|
||||
local function gui_opened(event)
|
||||
@ -483,7 +499,7 @@ local function gui_opened(event)
|
||||
this.players[player.index].data.item_frame = pane
|
||||
this.players[player.index].data.coins_left = coinsleft
|
||||
|
||||
redraw_market_items(pane, player)
|
||||
redraw_market_items(pane, player, search_text)
|
||||
end
|
||||
|
||||
local function gui_click(event)
|
||||
@ -514,7 +530,7 @@ local function gui_click(event)
|
||||
if slider_value > 1 then
|
||||
data.slider.slider_value = slider_value - 1
|
||||
data.text_input.text = data.slider.slider_value
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
return
|
||||
elseif name == 'more' then
|
||||
@ -522,7 +538,7 @@ local function gui_click(event)
|
||||
if slider_value <= 1e3 then
|
||||
data.slider.slider_value = slider_value + 1
|
||||
data.text_input.text = data.slider.slider_value
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -570,7 +586,7 @@ local function gui_click(event)
|
||||
this.health_upgrades = this.health_upgrades + item_count
|
||||
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
@ -605,7 +621,7 @@ local function gui_click(event)
|
||||
only_in_alt_mode = true
|
||||
}
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
@ -627,7 +643,7 @@ local function gui_click(event)
|
||||
this.xp_points_upgrade = this.xp_points_upgrade + item_count
|
||||
this.train_upgrades = this.train_upgrades + item_count
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
@ -664,7 +680,7 @@ local function gui_click(event)
|
||||
this.upgrades.flame_turret.limit = this.upgrades.flame_turret.limit + item_count
|
||||
this.upgrades.flame_turret.bought = this.upgrades.flame_turret.bought + item_count
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
@ -692,7 +708,7 @@ local function gui_click(event)
|
||||
this.upgrades.landmine.limit = this.upgrades.landmine.limit + item_count
|
||||
this.upgrades.landmine.bought = this.upgrades.landmine.bought + item_count
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
return
|
||||
end
|
||||
@ -707,7 +723,7 @@ local function gui_click(event)
|
||||
|
||||
RPG.rpg_reset_player(player, true)
|
||||
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
return
|
||||
end
|
||||
@ -722,7 +738,7 @@ local function gui_click(event)
|
||||
player.insert({name = item.value, count = cost})
|
||||
player.remove_item({name = name, count = inserted_count})
|
||||
end
|
||||
redraw_market_items(data.item_frame, player)
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
end
|
||||
end
|
||||
|
@ -34,6 +34,7 @@ local Collapse = require 'modules.collapse'
|
||||
local Difficulty = require 'modules.difficulty_vote'
|
||||
local Task = require 'utils.task'
|
||||
local Alert = require 'utils.alert'
|
||||
local AntiGrief = require 'antigrief'
|
||||
--local HD = require 'modules.hidden_dimension.main'
|
||||
|
||||
local Public = {}
|
||||
@ -199,6 +200,7 @@ function Public.reset_map()
|
||||
local this = WPT.get()
|
||||
local wave_defense_table = WD.get_table()
|
||||
local get_score = Score.get_table()
|
||||
local antigrief = AntiGrief.get()
|
||||
|
||||
for _, player in pairs(game.players) do
|
||||
if player.controller_type == defines.controllers.editor then
|
||||
@ -232,6 +234,8 @@ function Public.reset_map()
|
||||
global.friendly_fire_history = {}
|
||||
global.landfill_history = {}
|
||||
global.mining_history = {}
|
||||
AntiGrief.log_tree_harvest(true)
|
||||
AntiGrief.whitelist_types('tree', true)
|
||||
get_score.score_table = {}
|
||||
Diff.difficulty_poll_closing_timeout = game.tick + 90000
|
||||
Diff.difficulty_player_votes = {}
|
||||
@ -543,7 +547,7 @@ local chunk_load = function()
|
||||
if chunk_load_tick then
|
||||
if chunk_load_tick < game.tick then
|
||||
WPT.get().chunk_load_tick = nil
|
||||
Task.set_queue_speed(1)
|
||||
Task.set_queue_speed(4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -268,7 +268,10 @@ function Event.add_removable_function(event_name, func)
|
||||
end
|
||||
|
||||
if Debug.is_closure(func) then
|
||||
error('func cannot be a closure as that is a desync risk. Consider using Event.add_removable(event_name, token) instead.', 2)
|
||||
error(
|
||||
'func cannot be a closure as that is a desync risk. Consider using Event.add_removable(event_name, token) instead.',
|
||||
2
|
||||
)
|
||||
end
|
||||
|
||||
local funcs = function_handlers[event_name]
|
||||
@ -375,7 +378,10 @@ function Event.add_removable_nth_tick_function(tick, func)
|
||||
end
|
||||
|
||||
if Debug.is_closure(func) then
|
||||
error('func cannot be a closure as that is a desync risk. Consider using Event.add_removable_nth_tick(tick, token) instead.', 2)
|
||||
error(
|
||||
'func cannot be a closure as that is a desync risk. Consider using Event.add_removable_nth_tick(tick, token) instead.',
|
||||
2
|
||||
)
|
||||
end
|
||||
|
||||
local funcs = function_nth_tick_handlers[tick]
|
||||
@ -429,15 +435,15 @@ function Event.generate_event_name(name)
|
||||
end
|
||||
|
||||
function Event.add_event_filter(event, filter)
|
||||
local current_filters = script.get_event_filter(event)
|
||||
local current_filters = script.get_event_filter(event)
|
||||
|
||||
if not current_filters then
|
||||
current_filters = {filter}
|
||||
else
|
||||
table.insert(current_filters, filter)
|
||||
end
|
||||
if not current_filters then
|
||||
current_filters = {filter}
|
||||
else
|
||||
table.insert(current_filters, filter)
|
||||
end
|
||||
|
||||
script.set_event_filter(event, current_filters)
|
||||
script.set_event_filter(event, current_filters)
|
||||
end
|
||||
|
||||
local function add_handlers()
|
||||
|
Loading…
Reference in New Issue
Block a user