Commit 4078977abb37c79618647161fe3454e197c757c3
1 parent
3ef575ee
Prepare for first release to mod portal
Showing
8 changed files
with
103 additions
and
223 deletions
.vscode/launch.json
0 → 100644
| 1 | +{ | |
| 2 | + // Use IntelliSense to learn about possible attributes. | |
| 3 | + // Hover to view descriptions of existing attributes. | |
| 4 | + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
| 5 | + "version": "0.2.0", | |
| 6 | + "configurations": [ | |
| 7 | + { | |
| 8 | + "type": "factoriomod", | |
| 9 | + "request": "launch", | |
| 10 | + "name": "Factorio Mod Debug", | |
| 11 | + "modsPath": "C:/Program Files/Factorio/mods", | |
| 12 | + "configPath": "C:/Program Files/Factorio/config/config.ini", | |
| 13 | + "factorioPath": "C:/Program Files/Factorio/bin/x64/factorio.exe" | |
| 14 | + } | |
| 15 | + ] | |
| 16 | +} | |
| 0 | 17 | \ No newline at end of file | ... | ... |
CHANGELOG.md
0 → 100644
| 1 | +# Changelog | |
| 2 | +All notable changes to this project will be documented in this file. | |
| 3 | + | |
| 4 | +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |
| 5 | +and this project adheres to the versioning of Factorio, so 0.18.x will be at least compatible / tested with Factorio 0.18.x. | |
| 6 | + | |
| 7 | +## [Released] | |
| 8 | + | |
| 9 | +## [0.18.0] - 2020-06-06 | |
| 10 | +### General | |
| 11 | +- Initial Release of the mod | |
| 12 | +- Compatible with Factorio >0.18.0; tested on 0.18.30 | |
| 13 | +- Based on the 4-Function Calculator found in the [Max Rate Calculator](https://mods.factorio.com/mod/MaxRateCalculator) mod by [Theanderblast](https://mods.factorio.com/user/theanderblast) | |
| 14 | + | |
| 15 | +### Added | |
| 16 | +- History of recent calculations | |
| 17 | +- Possibility to copy recent calculations to the current one (with shift+left-click) | |
| 18 | +- Substitutes some functions & "constants" of the Lua [math-lib](http://lua-users.org/wiki/MathLibraryTutorial) | |
| 19 | + - abs() -> math.abs() | |
| 20 | + - acos() -> math.acos() | |
| 21 | + - asin() -> math.asin() | |
| 22 | + - atan() -> math.atan() | |
| 23 | + - ceil() -> math.ceil() | |
| 24 | + - floor() -> math.floor() | |
| 25 | + - cos() -> math.cos() | |
| 26 | + - sin() -> math.sin() | |
| 27 | + - tan() -> math.tan() | |
| 28 | + - deg() -> math.deg() | |
| 29 | + - rad() -> math.rad() | |
| 30 | + - exp() -> math.exp() | |
| 31 | + - log() -> math.log() | |
| 32 | + - min() -> math.min() | |
| 33 | + - max() -> math.max() | |
| 34 | + - modf() -> math.modf() | |
| 35 | + - sqrt() -> math.sqrt() | |
| 36 | + - huge -> math.huge | |
| 37 | + - pi -> math.pi | |
| 38 | +- Allows the use of "%" (percent sign) in the calculation | |
| 39 | +- A little easter egg :-) | |
| 40 | +- Setting for number of decimal places in result (Default: 2). Exact value will be displayed in the tooltip | |
| 41 | +- Setting if triggering the calculation should clear the current equation (Default: no) | |
| 42 | + | |
| 43 | +### Changed | |
| 44 | +- Made the buttons slightly bigger, so that it's better readable on streams. | |
| 45 | +- Allows to make "complex" calculations with parentheses | |
| 46 | +- Allows pretty much all characters in the equation field | |
| 47 | + - but the "=" (equal sign) will trigger the calculation | |
| 48 | + | |
| 49 | +### Removed | |
| 50 | +- Got rid of the memory functions - but introduced the list of recent calculations instead | |
| 0 | 51 | \ No newline at end of file | ... | ... |
README.md
0 → 100644
| 1 | +# Calculator UI | |
| 2 | + | |
| 3 | +Calculator UI is a Factorio mod which adds a calculator to the Factorio game with the goal to have a little bit of usability behind it. | |
| 4 | + | |
| 5 | +## Based on | |
| 6 | +The 4-Function Calculator found in the [Max Rate Calculator](https://mods.factorio.com/mod/MaxRateCalculator) mod by [Theanderblast](https://mods.factorio.com/user/theanderblast). | |
| 7 | + | |
| 8 | +## Features | |
| 9 | +- List of recent calculations | |
| 10 | +- Use of parentheses in the equation | |
| 11 | +- rounding of numbers (number of decimal places can be set in the settings) | |
| 12 | +- copy a recent calculation into the current calculation (by shift+left-click on the equation you want to copy) | |
| 13 | +- a nifty little easter egg ;-) | |
| 14 | +- use of some advanced function and constants of the Lua [math-lib](http://lua-users.org/wiki/MathLibraryTutorial) (without math.) -> e.g. "pi" instead of "math.pi". | |
| 15 | + | |
| 16 | +## Installation | |
| 17 | +Well ... ehm ... search for the mod ingame and install it :-) | |
| 18 | + | |
| 19 | +## Usage | |
| 20 | +Press the 3 little dots on the shortcuts UI of Factorio to select the "Calculator". Afterwards you can click on the calculator symbol to open it. | |
| 21 | + | |
| 22 | +## Changelog | |
| 23 | +see separate [changelog](changelog.md) | |
| 24 | + | |
| 25 | +## License | |
| 26 | +[MIT](https://choosealicense.com/licenses/mit/) | |
| 0 | 27 | \ No newline at end of file | ... | ... |
calculator.lua
| ... | ... | @@ -218,8 +218,8 @@ function fix_equation(equation) |
| 218 | 218 | ["tan"] = "math.tan", |
| 219 | 219 | ["deg"] = "math.deg", |
| 220 | 220 | ["rad"] = "math.rad", |
| 221 | - ["exp"] = "math.log", | |
| 222 | - ["exp"] = "math.log", | |
| 221 | + ["exp"] = "math.exp", | |
| 222 | + ["log"] = "math.log", | |
| 223 | 223 | ["min"] = "math.min", |
| 224 | 224 | ["max"] = "math.max", |
| 225 | 225 | ["modf"] = "math.modf", |
| ... | ... | @@ -292,6 +292,10 @@ function process_equal_key(player, button) |
| 292 | 292 | end |
| 293 | 293 | end |
| 294 | 294 | end |
| 295 | + | |
| 296 | + if settings.get_player_settings(player)["calcui-clear-on-calc"].value then | |
| 297 | + clear_equation(player) | |
| 298 | + end | |
| 295 | 299 | end |
| 296 | 300 | |
| 297 | 301 | -- ---------------------------------------------------------------- |
| ... | ... | @@ -390,194 +394,4 @@ function calcui_on_gui_location_changed(event) |
| 390 | 394 | local root = get_gui_root(player) |
| 391 | 395 | root.calcui.location = event.element.location |
| 392 | 396 | end |
| 393 | -end | |
| 394 | - | |
| 395 | - | |
| 396 | - | |
| 397 | - | |
| 398 | - | |
| 399 | - | |
| 400 | --- -- ---------------------------------------------------------------- | |
| 401 | --- local function process_number_key(player, num) | |
| 402 | - -- debug_print("process_number_key(" .. num .. ")") | |
| 403 | - | |
| 404 | - -- if global.calcui_context[player.index].in_left_of_decimal then | |
| 405 | - -- val = num / global.calcui_context[player.index].decimal_place | |
| 406 | - -- if global.calcui_context[player.index].in_data_entry then | |
| 407 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].current_value + val | |
| 408 | - -- else | |
| 409 | - -- global.calcui_context[player.index].current_value = val | |
| 410 | - -- end | |
| 411 | - -- global.calcui_context[player.index].decimal_place = global.calcui_context[player.index].decimal_place * 10 | |
| 412 | - -- else | |
| 413 | - -- if global.calcui_context[player.index].in_data_entry then | |
| 414 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].current_value * 10 + num | |
| 415 | - -- else | |
| 416 | - -- global.calcui_context[player.index].current_value = tonumber(num) | |
| 417 | - -- end | |
| 418 | - -- end | |
| 419 | - -- global.calcui_context[player.index].in_data_entry = true | |
| 420 | - -- update_display(player) | |
| 421 | --- end | |
| 422 | - | |
| 423 | --- -- ---------------------------------------------------------------- | |
| 424 | --- local function process_decimal_key(player, key) | |
| 425 | - -- debug_print("process_decimal_key(" .. key .. ")") | |
| 426 | - -- if global.calcui_context[player.index].in_left_of_decimal then | |
| 427 | - -- return | |
| 428 | - -- end | |
| 429 | - | |
| 430 | - -- global.calcui_context[player.index].in_left_of_decimal = true | |
| 431 | - -- global.calcui_context[player.index].decimal_place = 10 | |
| 432 | - -- update_display(player) | |
| 433 | --- end | |
| 434 | - | |
| 435 | --- -- ---------------------------------------------------------------- | |
| 436 | --- local function process_change_sign_key(player, key) | |
| 437 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].current_value * -1 | |
| 438 | - -- update_display(player) | |
| 439 | --- end | |
| 440 | - | |
| 441 | --- -- ---------------------------------------------------------------- | |
| 442 | --- local function process_equal_key(player, key) | |
| 443 | - -- debug_print("process_equal_key(" .. key .. ") global.calcui_context[player.index].current_func is " .. global.calcui_context[player.index].current_func) | |
| 444 | - | |
| 445 | - -- global.calcui_context[player.index].in_data_entry = false | |
| 446 | - -- doing_decimal = false | |
| 447 | - | |
| 448 | - -- if global.calcui_context[player.index].current_func == "ADD" then | |
| 449 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].operand + global.calcui_context[player.index].current_value | |
| 450 | - -- elseif global.calcui_context[player.index].current_func == "SUB" then | |
| 451 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].operand - global.calcui_context[player.index].current_value | |
| 452 | - -- elseif global.calcui_context[player.index].current_func == "MUL" then | |
| 453 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].operand * global.calcui_context[player.index].current_value | |
| 454 | - -- elseif global.calcui_context[player.index].current_func == "DIV" then | |
| 455 | - -- debug_print("process_equal_key global.calcui_context[player.index].current_value " .. global.calcui_context[player.index].current_value) | |
| 456 | - | |
| 457 | - -- if global.calcui_context[player.index].current_value == 0 then | |
| 458 | - -- debug_print("process_equal_key DIVIDE BY ZERO") | |
| 459 | - -- update_display(player, {"calcui_divide_by_zero"}) -- TODO: localize | |
| 460 | - -- return | |
| 461 | - -- end | |
| 462 | - -- global.calcui_context[player.index].current_value = global.calcui_context[player.index].operand / global.calcui_context[player.index].current_value | |
| 463 | - -- end | |
| 464 | - -- global.calcui_context[player.index].current_func = "" | |
| 465 | - -- global.calcui_context[player.index].in_data_entry = false | |
| 466 | - -- update_display(player) | |
| 467 | --- end | |
| 468 | - | |
| 469 | --- -- ---------------------------------------------------------------- | |
| 470 | --- local function process_func_key(player, key) | |
| 471 | - -- debug_print("process_func_key(" .. key .. ")") | |
| 472 | - | |
| 473 | - -- if global.calcui_context[player.index].current_func ~= "" then | |
| 474 | - -- process_equal_key(player, key) | |
| 475 | - -- end | |
| 476 | - | |
| 477 | - -- global.calcui_context[player.index].current_func = key | |
| 478 | - -- global.calcui_context[player.index].operand = global.calcui_context[player.index].current_value | |
| 479 | - -- global.calcui_context[player.index].in_data_entry = false | |
| 480 | - -- global.calcui_context[player.index].in_left_of_decimal = false | |
| 481 | --- end | |
| 482 | - | |
| 483 | --- -- ---------------------------------------------------------------- | |
| 484 | --- local function process_mem_key(player, key) | |
| 485 | - -- debug_print("process_mem_key(" .. key .. ")") | |
| 486 | - -- if calculator_memory == nil then | |
| 487 | - -- debug_print("process_mem_key(" .. key .. ") calculator_memory was nil") | |
| 488 | - -- calculator_memory = 0 | |
| 489 | - -- end | |
| 490 | - -- if key == "MS" then | |
| 491 | - -- calculator_memory = global.calcui_context[player.index].current_value | |
| 492 | - -- elseif key == "M+" then | |
| 493 | - -- calculator_memory = calculator_memory + global.calcui_context[player.index].current_value | |
| 494 | - -- elseif key == "M-" then | |
| 495 | - -- calculator_memory = calculator_memory - global.calcui_context[player.index].current_value | |
| 496 | - -- else | |
| 497 | - -- global.calcui_context[player.index].current_value = calculator_memory | |
| 498 | - -- end | |
| 499 | - -- global.calcui_context[player.index].in_data_entry = false | |
| 500 | - -- update_display(player) | |
| 501 | --- end | |
| 502 | - | |
| 503 | --- -- ---------------------------------------------------------------- | |
| 504 | --- local function process_edit_key(player, key) | |
| 505 | - -- debug_print("process_edit_key(" .. key .. ")") | |
| 506 | - -- if key == "CE" then | |
| 507 | - -- global.calcui_context[player.index].current_value = 0 | |
| 508 | - -- elseif key == "C" then | |
| 509 | - -- init_calculator(player) | |
| 510 | - -- end | |
| 511 | - -- global.calcui_context[player.index].in_data_entry = false | |
| 512 | - -- update_display(player) | |
| 513 | --- end | |
| 514 | - | |
| 515 | --- -- ---------------------------------------------------------------- | |
| 516 | --- local function set_current_value_to_text(player, text) | |
| 517 | - -- local last_char = string.sub(text, -1) | |
| 518 | - -- if last_char == "+" then | |
| 519 | - -- process_func_key(player, "ADD") | |
| 520 | - -- elseif last_char == "-" then | |
| 521 | - -- process_func_key(player, "SUB") | |
| 522 | - -- elseif last_char == "*" then | |
| 523 | - -- process_func_key(player, "MUL") | |
| 524 | - -- elseif last_char == "/" then | |
| 525 | - -- process_func_key(player, "DIV") | |
| 526 | - -- else | |
| 527 | - -- -- number | |
| 528 | - -- local val = tonumber(text) | |
| 529 | - -- if val ~= nil then | |
| 530 | - -- global.calcui_context[player.index].current_value = val | |
| 531 | - -- debug_print("set_current_value_to_text got value " .. text) | |
| 532 | - -- local plain_text = true | |
| 533 | - -- local dot = string.find(text, '.', 1, plain_text) | |
| 534 | - -- if dot ~= nil then | |
| 535 | - -- local number_decimal_places = #text - dot | |
| 536 | - -- global.calcui_context[player.index].decimal_place = 10 ^ (number_decimal_places + 1) | |
| 537 | - -- global.calcui_context[player.index].in_left_of_decimal = true | |
| 538 | - -- debug_print("#text " .. #text .. " number_global.calcui_context[player.index].decimal_places " .. | |
| 539 | - -- number_decimal_places .. " global.calcui_context[player.index].decimal_place " .. global.calcui_context[player.index].decimal_place .. " dot " .. dot .. " in_lod " .. boolstr(global.calcui_context[player.index].in_left_of_decimal)) | |
| 540 | - -- else | |
| 541 | - -- debug_print("set_current_value_to_text no dot. set lod to false" ) | |
| 542 | - -- global.calcui_context[player.index].in_left_of_decimal = false | |
| 543 | - -- end | |
| 544 | - -- else | |
| 545 | - -- debug_print("got junk") | |
| 546 | - -- end | |
| 547 | - -- end | |
| 548 | --- end | |
| 549 | - | |
| 550 | --- -- ---------------------------------------------------------------- | |
| 551 | --- local function process_backspace_key(player, key) | |
| 552 | - -- local root = get_gui_root(player) | |
| 553 | - -- debug_print("process_backspace_key(" .. key .. ")") | |
| 554 | - -- local old_text = root.calcui.calcui_display.caption | |
| 555 | - -- local old_len = #old_text | |
| 556 | - -- text = string.sub(old_text, 1, old_len -1) | |
| 557 | - -- debug_print("process_backspace_key(" .. key .. ") old_text " .. old_text .. " old_len " .. old_len .. " text " .. text .. | |
| 558 | - -- " in_decimal " .. boolstr(global.calcui_context[player.index].in_left_of_decimal) .. " global.calcui_context[player.index].decimal_place " .. global.calcui_context[player.index].decimal_place) | |
| 559 | - -- if #text == 0 then | |
| 560 | - -- global.calcui_context[player.index].current_value = 0 | |
| 561 | - -- else | |
| 562 | - -- set_current_value_to_text(player, text) | |
| 563 | - -- end | |
| 564 | - -- update_display(player) | |
| 565 | --- end | |
| 566 | - | |
| 567 | --- -- ---------------------------------------------------------------- | |
| 568 | --- local function calcui_toggle_key(event) | |
| 569 | - -- local player = game.players[event.player_index] | |
| 570 | - -- toggle_calculator(player) | |
| 571 | --- end | |
| 572 | - | |
| 573 | --- -- ---------------------------------------------------------------- | |
| 574 | --- function calcui_clickable_value_clicked(player, val) -- a value in the main Max Rate Calculator has been clicked on. Paste into current value | |
| 575 | - -- local root = get_gui_root(player) | |
| 576 | - -- if root ~=nil and root.calcui ~= nil then | |
| 577 | - -- local text = tostring(val) | |
| 578 | - -- set_current_value_to_text(player, text) | |
| 579 | - -- update_display(player) | |
| 580 | - -- end | |
| 581 | --- end | |
| 582 | - | |
| 583 | --- script.on_event( "calcui_toggle", calcui_toggle_key ) | |
| 584 | 397 | \ No newline at end of file |
| 398 | +end | |
| 585 | 399 | \ No newline at end of file | ... | ... |
control.lua
| ... | ... | @@ -28,7 +28,6 @@ end |
| 28 | 28 | |
| 29 | 29 | -- ---------------------------------------------------------------- |
| 30 | 30 | local function get_gui_root(player) |
| 31 | - -- return player.gui.left | |
| 32 | 31 | return player.gui.screen |
| 33 | 32 | end |
| 34 | 33 | |
| ... | ... | @@ -52,10 +51,7 @@ end |
| 52 | 51 | local function on_gui_click(event) |
| 53 | 52 | local event_name = event.element.name |
| 54 | 53 | debug_print("event_name " .. event_name) |
| 55 | - -- local calcui_prefix = "calcui_" | |
| 56 | - -- local possible_calcui_prefix = string.sub( event_name, 1, string.len(calcui_prefix) ) | |
| 57 | 54 | local player = game.players[event.player_index] |
| 58 | - -- local root = get_gui_root(player) | |
| 59 | 55 | |
| 60 | 56 | local calcui_prefix = "calcui_" |
| 61 | 57 | local possible_marcalc_prefix = string.sub( event_name, 1, string.len(calcui_prefix)) |
| ... | ... | @@ -63,25 +59,6 @@ local function on_gui_click(event) |
| 63 | 59 | handle_calcui_click(event, player) |
| 64 | 60 | return |
| 65 | 61 | end |
| 66 | - | |
| 67 | - -- if possible_calcui_prefix == calcui_prefix then | |
| 68 | - -- if event_name == "calcui_calculator_button" then | |
| 69 | - -- toggle_calculator(player) | |
| 70 | - -- return | |
| 71 | - -- end | |
| 72 | - | |
| 73 | - -- if root.calcui_gui_top then | |
| 74 | - -- if event_name == "calcui_close_button" then | |
| 75 | - -- destroy_calcui_gui(player) | |
| 76 | - -- hide_calculator(player) | |
| 77 | - -- end | |
| 78 | - -- elseif event_name == "calcui_close_button" then | |
| 79 | - -- if player.gui.left.calcui_gui_top then | |
| 80 | - -- player.gui.left.calcui_gui_top.destroy() | |
| 81 | - -- hide_calculator(player) | |
| 82 | - -- end | |
| 83 | - -- end | |
| 84 | - -- end | |
| 85 | 62 | end |
| 86 | 63 | |
| 87 | 64 | -- ---------------------------------------------------------------- |
| ... | ... | @@ -90,9 +67,6 @@ local function on_gui_confirmed(event) |
| 90 | 67 | player = game.players[event.player_index]; |
| 91 | 68 | if event.element.name == "calcui_display" then |
| 92 | 69 | process_equal_key(player) |
| 93 | - if settings.get_player_settings(player)["calcui-enter-clear"].value then | |
| 94 | - clear_equation(player) | |
| 95 | - end | |
| 96 | 70 | end |
| 97 | 71 | end |
| 98 | 72 | |
| ... | ... | @@ -118,4 +92,4 @@ script.on_event( defines.events.on_gui_click, on_gui_click) |
| 118 | 92 | script.on_event( defines.events.on_gui_confirmed, on_gui_confirmed) |
| 119 | 93 | script.on_event( defines.events.on_gui_text_changed, calcui_on_gui_text_changed ) |
| 120 | 94 | script.on_event( defines.events.on_gui_location_changed, calcui_on_gui_location_changed ) |
| 121 | -commands.add_command( "calcui", "Max Rate Calculator [ debug | nodebug ] ", on_calcui_command ) | |
| 122 | 95 | \ No newline at end of file |
| 96 | +commands.add_command( "calcui", "Calculator UI [ debug | nodebug ] ", on_calcui_command ) | |
| 123 | 97 | \ No newline at end of file | ... | ... |
locale/en/config.cfg
| ... | ... | @@ -3,11 +3,11 @@ calcui_4func=Calculator |
| 3 | 3 | |
| 4 | 4 | [mod-setting-name] |
| 5 | 5 | calcui-decimal-places=Decimal places |
| 6 | -calcui-enter-clear=Clear equation on enter? | |
| 6 | +calcui-clear-on-calc=Clear equation on calculation | |
| 7 | 7 | |
| 8 | 8 | [mod-settings-description] |
| 9 | 9 | calcui-decimal-places=Number of decimal places in the result |
| 10 | -calcui-enter-clear=Should pressing the enter key delete the equation? | |
| 10 | +calcui-clear-on-calc=Should trigger the calculation delete the equation? | |
| 11 | 11 | |
| 12 | 12 | [calculator-ui] |
| 13 | 13 | title=Calculator | ... | ... |
settings.lua
thumbnail.png
0 → 100644
17.7 KB