Skip to content

Commit

Permalink
Update to 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwerOxotnik committed Aug 31, 2021
1 parent c41c413 commit 578420c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 0.7.0
Date: 2021-08-24
Changes:
- EasyAPI is optional instead of "Multiplayer Trading" mod
---------------------------------------------------------------------------------------------------
Version: 0.6.2
Date: 2021-08-24
Changes:
Expand Down
14 changes: 7 additions & 7 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ end
function CalculatePercentageValue(value, type, item, force, player)
local factor = value * 0.01
if type == PERCENTAGE_TYPE_BALANCE then
return MultiplayerTrading.get_balance(force) * factor
return EasyAPI.get_balance(force) * factor
elseif type == PERCENTAGE_TYPE_PLAYER_COUNT then
local count = 0
for _, tech in pairs(game.players) do count = count + 1 end
Expand Down Expand Up @@ -971,7 +971,7 @@ function ExecuteEffect(law, effect, event)
count = math.floor(value)
}
elseif effect.effect_reward_type == EFFECT_REWARD_TYPE_MONEY then
MultiplayerTrading.add_to_balance(force, value)
EasyAPI.add_to_balance(force, value)
end
elseif effect.effect_type == EFFECT_TYPE_FINE then
if effect.effect_fine_type == EFFECT_FINE_TYPE_INVENTORY then
Expand All @@ -985,9 +985,9 @@ function ExecuteEffect(law, effect, event)
count = math.floor(value)
}
elseif effect.effect_fine_type == EFFECT_FINE_TYPE_MONEY then
local balance = MultiplayerTrading.get_balance(force)
local balance = EasyAPI.get_balance(force)
event.fine_success = (balance >= value)
MultiplayerTrading.add_to_balance(force, -value)
EasyAPI.add_to_balance(force, -value)
end
elseif effect.effect_type == EFFECT_TYPE_FINE_FAIL then
event.stop_effects = (event.fine_success == true or event.fine_success == nil)
Expand Down Expand Up @@ -1765,7 +1765,7 @@ function CreateEffectGUI(parent, effect, read_only)
}
CreateValueFields(gui, effect, "effect_", read_only)
elseif effect.effect_fine_type == EFFECT_FINE_TYPE_MONEY then
if MultiplayerTrading.is_loaded() then
if EasyAPI.is_loaded() then
CreateValueFields(gui, effect, "effect_", read_only)
else
gui.add{
Expand Down Expand Up @@ -1798,7 +1798,7 @@ function CreateEffectGUI(parent, effect, read_only)
}
CreateValueFields(gui, effect, "effect_", read_only)
else
if MultiplayerTrading.is_loaded() then
if EasyAPI.is_loaded() then
CreateValueFields(gui, effect, "effect_", read_only)
else
gui.add{
Expand Down Expand Up @@ -1896,7 +1896,7 @@ function CreateValueFields(gui, clause, prefix, read_only)
read_only = read_only,
label_style = "menu_message"
}
if pct_type == PERCENTAGE_TYPE_BALANCE and not MultiplayerTrading.is_loaded() then
if pct_type == PERCENTAGE_TYPE_BALANCE and not EasyAPI.is_loaded() then
local missing = gui.add{
type = "label",
caption = {"lawful-evil.multiplayer-trading.missing"}
Expand Down
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "m-lawful-evil",
"version": "0.6.2",
"version": "0.7.0",
"factorio_version": "1.1",
"title": "Lawful Evil",
"author": "Luke Perkin",
Expand All @@ -9,6 +9,6 @@
"source": "https://github.com/ZwerOxotnik/lawful-evil",
"dependencies": [
"base",
"? m-multiplayertrading"
"? EasyAPI"
]
}
24 changes: 12 additions & 12 deletions mpt.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
MultiplayerTrading = {
mod_id = "multiplayer-trading"
}
local call = remote.call

function MultiplayerTrading.is_loaded()
return game.active_mods["multiplayertrading"] ~= nil
EasyAPI = {}

function EasyAPI.is_loaded()
return game.active_mods["EasyAPI"] ~= nil
end

function MultiplayerTrading.add_to_balance(force, amount)
if MultiplayerTrading.is_loaded() then
remote.call(MultiplayerTrading.mod_id, "add-money", force, amount)
function EasyAPI.add_to_balance(force, amount)
if EasyAPI.is_loaded() then
call("EasyAPI", "deposit_force_money", force, amount)
end
end

function MultiplayerTrading.get_balance(force)
if MultiplayerTrading.is_loaded() then
return remote.call(MultiplayerTrading.mod_id, "get-money", force)
function EasyAPI.get_balance(force)
if EasyAPI.is_loaded() then
return (call("EasyAPI", "get_force_money", force.index) or 0)
end
return 0
end
end

0 comments on commit 578420c

Please sign in to comment.