### Performing Async HTTP GET Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md An asynchronous function for performing HTTP GET requests within the sandbox environment. Note that this is an empty implementation and may not perform actual requests or network communication. ```Lua async.httpGet ``` -------------------------------- ### Demonstrating WriteableBitmapEx Drawing and Manipulation (C#) Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/CsharpSimulator/STORMWORKS_Simulator/lib/WriteableBitmapEx/README.md This snippet provides a comprehensive example of using the WriteableBitmapEx library's extension methods in C#. It shows how to initialize, clear, load from resources, set/get pixels, draw various shapes (lines, triangles, rectangles, ellipses, polylines, curves), apply effects (Blit), use pixel-wise functions (ForEach), clone, save, crop, rotate, flip, and resize a WriteableBitmap object. It uses the BitmapFactory and WriteableBitmapExtensions static classes and the using statement with GetBitmapContext for efficient operation. ```C# // Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control WriteableBitmap writeableBmp = BitmapFactory.New(512, 512); ImageControl.Source = writeableBmp; using(writeableBmp.GetBitmapContext()) { // Load an image from the calling Assembly's resources via the relative path writeableBmp = BitmapFactory.New(1, 1).FromResource("Data/flower2.png"); // Clear the WriteableBitmap with white color writeableBmp.Clear(Colors.White); // Set the pixel at P(10, 13) to black writeableBmp.SetPixel(10, 13, Colors.Black); // Get the color of the pixel at P(30, 43) Color color = writeableBmp.GetPixel(30, 43); // Green line from P1(1, 2) to P2(30, 40) writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green); // Line from P1(1, 2) to P2(30, 40) using the fastest draw line method int[] pixels = writeableBmp.Pixels; int w = writeableBmp.PixelWidth; int h = writeableBmp.PixelHeight; WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor); // Blue anti-aliased line from P1(10, 20) to P2(50, 70) with a stroke of 5 writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue, 5); // Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10) writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black); // Red rectangle from the point P1(2, 4) that is 10px wide and 6px high writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red); // Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue); // Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8) int[] p = new int[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 }; writeableBmp.DrawPolyline(p, Colors.Green); // Cubic BeziƩr curve from P1(5, 5) to P4(20, 7) // with the control points P2(10, 15) and P3(15, 0) writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7, Colors.Purple); // Cardinal spline with a tension of 0.5 // through the points P1(10, 5), P2(20, 40) and P3(30, 30) int[] pts = new int[] { 10, 5, 20, 40, 30, 30}; writeableBmp.DrawCurve(pts, 0.5, Colors.Yellow); // A filled Cardinal spline with a tension of 0.5 // through the points P1(10, 5), P2(20, 40) and P3(30, 30) writeableBmp.FillCurveClosed(pts, 0.5, Colors.Green); // Blit a bitmap using the additive blend mode at P1(10, 10) writeableBmp.Blit(new Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive); // Override all pixels with a function that changes the color based on the coordinate writeableBmp.ForEach((x, y, color) => Color.FromArgb(color.A, (byte)(color.R / 2), (byte)(x * y), 100)); } // Invalidate and present in the Dispose call // Take snapshot var clone = writeableBmp.Clone(); // Save to a TGA image stream (file for example) writeableBmp.WriteTga(stream); // Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high var cropped = writeableBmp.Crop(5, 8, 10, 10); // Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy var rotated = writeableBmp.Rotate(90); // Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy var flipped = writeableBmp.Flip(FlipMode.Horizontal); // Resizes the WriteableBitmap to 200px wide and 300px high using bilinear interpolation var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear); ``` -------------------------------- ### Using Require Function to Include Code Libraries (Lua) Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/README.md This snippet demonstrates how to use the `require(...)` function added by the LifeBoatAPI extension. It shows how to include code from external files and libraries (e.g., TrapdoorLib, LifeBoatAPI, BeginnersLibrary) to organize projects better and reuse code across different microcontroller projects. It also includes example usage within `onTick` and `onTimerEnd` functions. ```Lua require("TrapdoorLib.Timers") require("LifeBoatAPI.Maths.LBAngles") require("BeginnersLibrary.Missiles.Guidance") timer = trapdoor_timer_start(onTimerEnd) function onTick() timer:onTick() end function onTimerEnd() timer:reset() local elevation = LBAngles_convertTurnsToRadians(input.getNumber(1)) BeginnersSetMissileElevationFunction(elevation) end ``` -------------------------------- ### Getting Boolean Input State Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Retrieves the boolean state (true/false) of a digital input channel. The simulator maps specific input indices (e.g., input 1) to corresponding key presses like 'E' or 'Q' to match in-game behavior. ```Lua input.getBool ``` -------------------------------- ### Getting Simulator Button Toggle State Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Retrieves the toggle state of a UI button within the simulator. This function is typically called from the 'onLBSimulatorTick' event handler to check button status. ```Lua simulator.getIsToggled ``` -------------------------------- ### Getting CPU Time Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md A standard Lua function re-enabled in the sandbox for timing purposes. It returns an approximation of the CPU time used by the program but does not work in the actual Stormworks game environment. ```Lua os.clock ``` -------------------------------- ### Getting Simulator Button Click State Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Retrieves the click state of a UI button within the simulator. This function is typically called from the 'onLBSimulatorTick' event handler to detect button presses. ```Lua simulator.getIsClicked ``` -------------------------------- ### Getting Simulator Slider Value Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Retrieves the current value of a UI slider within the simulator. This function is typically called from the 'onLBSimulatorTick' event handler to read slider positions. ```Lua simulator.getSlider ``` -------------------------------- ### Demonstrating Recommended vs. Poor Code Style for Minimization (Lua) Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/README.md This snippet illustrates the recommended code style for the LifeBoatAPI minimizer. It shows that writing clear, readable code with descriptive names (like `GetAngleBetweenTwoSurfaces`, `math.min`) is preferred over manually trying to shorten code (like `surfRot`, `m.min`) because the minimizer is optimized to process well-structured code effectively. ```Lua -- do this function GetAngleBetweenTwoSurfaces(surfaceA, surfaceB, rotationAngle) end a = math.min(1,0) -- instead of function surfRot(a,b,t) end m = math a = m.min(1,0) ``` -------------------------------- ### Setting Simulator Screen Size Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Sets the dimensions of the simulator screen, removing previous size restrictions. Requires width and height parameters. ```Lua simulator.setScreen ``` -------------------------------- ### Loading Lua Modules with require Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Loads a specified Lua module or library into the current script. The extension's sandbox and build process accurately simulate the game's 'require' functionality, handling paths, order, and quotes. ```Lua require ``` -------------------------------- ### Drawing Text Box on Screen Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Draws text within a defined box on the simulator screen. Supports optional type-hints for parameters and correctly interprets '\n' characters for newlines, matching the behavior in the actual game. ```Lua screen.drawTextBox ``` -------------------------------- ### Applying Extended Redundancy Removal with Nested Sections (Lua) Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/README.md This snippet demonstrates the extended syntax for redundancy removal (`---@section identifier number blockname`), useful for nested structures or class definitions. It shows how to define a class `myClass` and its methods using sections. The extended syntax allows associating the main class block with `myClass` (the identifier) and ensuring the entire block is considered for removal if `myClass` is unused, including nested sections for methods like `myClass_destroyAllHumans` and `myClass_killOrBeKilled`. ```Lua ---@class myClass : BaseClass ---@field size number ---@field name string ---@section myClass 1 _MYCLASS_ myClass = { new = function(this, s, n) return LBCopy(this, {size = s, name = n}) end ---@section myClass_destroyAllHumans myClass_destroyAllHumans = function() end ---@endsection ---@section myClass_killOrBeKilled myClass_killOrBeKilled = function() end ---@endsection } ---@endsection _MYCLASS_ ``` -------------------------------- ### Handling Simulator Tick Event Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md The primary event handler function called by the simulator environment each tick. It provides access to simulator state and allows interaction with UI elements like buttons and sliders. ```Lua onLBSimulatorTick ``` -------------------------------- ### Applying Basic Redundancy Removal with Sections (Lua) Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/README.md This snippet illustrates the basic functionality of the redundancy removal feature. Code blocks enclosed within `---@section Identifier` and `---@endsection` are checked for usage of the identifier. If `myFunction` is not called elsewhere, its block is removed. Subsequently, since `myFunction` called `myOtherFunction`, the call to `myOtherFunction` is also removed, leading to its section being removed as well, leaving only the code outside sections. ```Lua ---@section myOtherFunction function myOtherFunction(abc) return abc + "def" end; ---@endsection ---@section myFunction function myFunction(abc) myOtherFunction(abc) end; ---@endsection var a = 10; --end program ``` -------------------------------- ### Logging Debug Messages Lua Source: https://github.com/nameouschangey/stormworks_vscodeextension/blob/main/Extension/CHANGELOG.md Outputs debug messages to the VSCode DEBUG CONSOLE. This function is recommended over the standard 'print' function for debugging within the extension's simulator environment. ```Lua debug.log ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.