From fbf64a0404085a3395bdc7f47b772a4d57283376 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 6 Mar 2024 11:10:55 +0000 Subject: [PATCH] Pull in the remainder of CC:T 1.109.6 --- gradle.properties | 2 +- .../assets/cctweaked/lua/rom/apis/colors.lua | 9 +- .../assets/cctweaked/lua/rom/apis/window.lua | 32 +++---- .../cctweaked/lua/rom/help/changelog.md | 94 +++++++++++++++++++ .../assets/cctweaked/lua/rom/help/whatsnew.md | 8 +- 5 files changed, 122 insertions(+), 23 deletions(-) diff --git a/gradle.properties b/gradle.properties index f416ff0d1..8646e29d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,6 +4,6 @@ org.gradle.jvmargs=-Xmx3G -modVersion=1.108.1 +modVersion=1.109.6 mcVersion=1.4.7 diff --git a/src/main/resources/assets/cctweaked/lua/rom/apis/colors.lua b/src/main/resources/assets/cctweaked/lua/rom/apis/colors.lua index 70ab61784..b98ff8d75 100644 --- a/src/main/resources/assets/cctweaked/lua/rom/apis/colors.lua +++ b/src/main/resources/assets/cctweaked/lua/rom/apis/colors.lua @@ -353,7 +353,8 @@ end --[[- Converts the given color to a paint/blit hex character (0-9a-f). -This is equivalent to converting floor(log_2(color)) to hexadecimal. +This is equivalent to converting `floor(log_2(color))` to hexadecimal. Values +outside the range of a valid colour will error. @tparam number color The color to convert. @treturn string The blit hex code of the color. @@ -367,7 +368,11 @@ colors.toBlit(colors.red) ]] function toBlit(color) expect(1, color, "number") - return color_hex_lookup[color] or string.format("%x", math.floor(math.log(color, 2))) + local hex = color_hex_lookup[color] + if hex then return hex end + + if color < 0 or color > 0xffff then error("Colour out of range", 2) end + return string.format("%x", math.floor(math.log(color, 2))) end --[[- Converts the given paint/blit hex character (0-9a-f) to a color. diff --git a/src/main/resources/assets/cctweaked/lua/rom/apis/window.lua b/src/main/resources/assets/cctweaked/lua/rom/apis/window.lua index 848ccfb91..7be7aebaf 100644 --- a/src/main/resources/assets/cctweaked/lua/rom/apis/window.lua +++ b/src/main/resources/assets/cctweaked/lua/rom/apis/window.lua @@ -58,6 +58,17 @@ local type = type local string_rep = string.rep local string_sub = string.sub +--- A custom version of [`colors.toBlit`], specialised for the window API. +local function parse_color(color) + if type(color) ~= "number" then + -- By tail-calling expect, we ensure expect has the right error level. + return expect(1, color, "number") + end + + if color < 0 or color > 0xffff then error("Colour out of range", 3) end + return 2 ^ math.floor(math.log(color, 2)) +end + --[[- Returns a terminal object that is a space within the specified parent terminal object. This can then be used (or even redirected to) in the same manner as eg a wrapped monitor. Refer to [the term API][`term`] for a list of @@ -341,10 +352,7 @@ function create(parent, nX, nY, nWidth, nHeight, bStartVisible) end local function setTextColor(color) - if type(color) ~= "number" then expect(1, color, "number") end - if tHex[color] == nil then - error("Invalid color (got " .. color .. ")" , 2) - end + if tHex[color] == nil then color = parse_color(color) end nTextColor = color if bVisible then @@ -356,11 +364,7 @@ function create(parent, nX, nY, nWidth, nHeight, bStartVisible) window.setTextColour = setTextColor function window.setPaletteColour(colour, r, g, b) - if type(colour) ~= "number" then expect(1, colour, "number") end - - if tHex[colour] == nil then - error("Invalid color (got " .. colour .. ")" , 2) - end + if tHex[colour] == nil then colour = parse_color(colour) end local tCol if type(r) == "number" and g == nil and b == nil then @@ -385,10 +389,7 @@ function create(parent, nX, nY, nWidth, nHeight, bStartVisible) window.setPaletteColor = window.setPaletteColour function window.getPaletteColour(colour) - if type(colour) ~= "number" then expect(1, colour, "number") end - if tHex[colour] == nil then - error("Invalid color (got " .. colour .. ")" , 2) - end + if tHex[colour] == nil then colour = parse_color(colour) end local tCol = tPalette[colour] return tCol[1], tCol[2], tCol[3] end @@ -396,10 +397,7 @@ function create(parent, nX, nY, nWidth, nHeight, bStartVisible) window.getPaletteColor = window.getPaletteColour local function setBackgroundColor(color) - if type(color) ~= "number" then expect(1, color, "number") end - if tHex[color] == nil then - error("Invalid color (got " .. color .. ")", 2) - end + if tHex[color] == nil then color = parse_color(color) end nBackgroundColor = color end diff --git a/src/main/resources/assets/cctweaked/lua/rom/help/changelog.md b/src/main/resources/assets/cctweaked/lua/rom/help/changelog.md index a7117b5ea..d728ba46a 100644 --- a/src/main/resources/assets/cctweaked/lua/rom/help/changelog.md +++ b/src/main/resources/assets/cctweaked/lua/rom/help/changelog.md @@ -1,3 +1,97 @@ +# New features in CC: Tweaked 1.109.6 + +* Improve several Lua parser error messages. +* Allow addon mods to register `require`able modules. + +Several bug fixes: +* Fix weak tables becoming malformed when keys are GCed. + +# New features in CC: Tweaked 1.109.5 + +* Add a new `/computercraft-computer-folder` command to open a computer's folder + in singleplayer. + +Several bug fixes: +* Discard characters being typed into the editor when closing `edit`'s `Run` screen. + +# New features in CC: Tweaked 1.109.4 + +Several bug fixes: +* Don't log warnings when a computer allocates no bytes. +* Fix incorrect list index in command computer's NBT conversion (lonevox). +* Fix `endPage()` not updating the printer's block state. +* Several documentation improvements (znepb). +* Correctly mount disks before computer startup, not afterwards. +* Update to Cobalt 0.9 + * Debug hooks are now correctly called for every function. + * Fix several minor inconsistencies with `debug.getinfo`. + * Fix Lua tables being sized incorrectly when created from varargs. + +# New features in CC: Tweaked 1.109.3 + +* Command computers now display in the operator items creative tab. + +Several bug fixes: +* Error if too many websocket messages are queued to be sent at once. +* Fix trailing-comma on method calls (e.g. `x:f(a, )` not using our custom error message. +* Fix internal compiler error when using `goto` as the first statement in an `if` block. +* Fix incorrect resizing of a tables' hash part when adding and removing keys. + +# New features in CC: Tweaked 1.109.2 + +* `math.random` now uses Lua 5.4's random number generator. + +Several bug fixes: +* Fix errors involving `goto` statements having the wrong line number. + +# New features in CC: Tweaked 1.109.1 + +Several bug fixes: +* Fix `mouse_drag` event not firing for right and middle mouse buttons. +* Fix crash when syntax errors involve `goto` or `::`. +* Fix deadlock occuring when adding/removing observers. +* Allow placing seeds into compostor barrels with `turtle.place()`. + +# New features in CC: Tweaked 1.109.0 + +* Update to Lua 5.2 + * `getfenv`/`setfenv` now only work on Lua functions. + * Add support for `goto`. + * Remove support for dumping and loading binary chunks. +* File handles, HTTP requests and websocket messages now use raw bytes rather than converting to UTF-8. +* Add `allow_repetitions` option to `textutils.serialiseJSON`. +* Track memory allocated by computers. + +Several bug fixes: +* Fix error when using position captures and backreferences in string patterns (e.g. `()(%1)`). +* Fix formatting non-real numbers with `%d`. + +# New features in CC: Tweaked 1.108.4 + +* Rewrite `@LuaFunction` generation to use `MethodHandle`s instead of ASM. +* Refactor `ComputerThread` to provide a cleaner interface. +* Remove `disable_lua51_features` config option. +* Update several translations (Sammy). + +Several bug fixes: +* Fix monitor peripheral becoming "detached" after breaking and replacing a monitor. +* Fix signs being empty when placed. +* Fix several inconsistencies with mount error messages. + +# New features in CC: Tweaked 1.108.3 + +Several bug fixes: +* Fix disconnect when joining a dedicated server. + +# New features in CC: Tweaked 1.108.2 + +* Add a tag for which blocks wired modems should ignore. + +Several bug fixes: +* Fix monitors sometimes being warped after resizing. +* Fix the skull recipes using the wrong UUID format. +* Fix paint canvas not always being redrawn after a term resize. + # New features in CC: Tweaked 1.108.1 Several bug fixes: diff --git a/src/main/resources/assets/cctweaked/lua/rom/help/whatsnew.md b/src/main/resources/assets/cctweaked/lua/rom/help/whatsnew.md index 482cb7a40..4a57b064e 100644 --- a/src/main/resources/assets/cctweaked/lua/rom/help/whatsnew.md +++ b/src/main/resources/assets/cctweaked/lua/rom/help/whatsnew.md @@ -1,7 +1,9 @@ -New features in CC: Tweaked 1.108.1 +New features in CC: Tweaked 1.109.6 + +* Improve several Lua parser error messages. +* Allow addon mods to register `require`able modules. Several bug fixes: -* Prevent no-opped players breaking or placing command computers. -* Allow using `@LuaFunction`-annotated methods on classes defined in child classloaders. +* Fix weak tables becoming malformed when keys are GCed. Type "help changelog" to see the full version history.