### Keyframe System Start Source: https://g-js-api.github.io/G.js/module-keyframes Starts the animation of a keyframe system. ```APIDOC ## start() ### Description Starts a keyframe system animation. ### Method start ### Parameters This method does not take any parameters. ### Response #### Success Response (200) - **status** (string) - Indicates that the keyframe system has started. ``` -------------------------------- ### Install G.js using npm Source: https://g-js-api.github.io/G.js/index To use G.js in your project, you need to have Node.js installed. Then, you can install the library by running the following npm command in your project's directory. ```bash npm install @g-js-api/g.js ``` -------------------------------- ### Create Keyframe System - JavaScript Source: https://g-js-api.github.io/G.js/lib_keyframes.js This function creates a keyframe system for animating a group of objects. It returns an object with `keyframe` and `start` methods to define and initiate the animation sequence. The `keyframe` method adds individual keyframes with specified positions, duration, curve, and easing, while the `start` method initiates the animation. ```javascript let ksys_id = 1; /** * Creates a keyframe system * @param {group} group Group of objects to animate * @returns {keyframe_system} */ let keyframe_system = (gr, same = false) => { let ksys_gr = same ? gr : unknown_g(); let oi = 0; let tksys_id = ksys_id; let o = { keyframe: (x, y, duration = 0.50, curve = false, close = false, easing = NONE) => { let o = object({ OBJ_ID: 3032, X: x, Y: y, DURATION: duration, CURVE: curve, CLOSE_LOOP: close, GROUPS: ksys_gr, ANIM_ID: tksys_id, EASING: easing, 524: 1, ACTIVE_TRIGGER: 1, 155: 2 }); if (oi > 0) o.obj_props.ORDER_INDEX = oi; $.add(o); oi++; }, start: () => { $.add(trigger({ OBJ_ID: 3033, ANIMATION_GID: ksys_gr, TARGET: gr, TIME_MOD: 1, POSITION_X_MOD: 1, POSITION_Y_MOD: 1, ROTATION_MOD: 1, SCALE_X_MOD: 1, SCALE_Y_MOD: 1 })); }, anim_id: ksys_id }; ksys_id++; return o }; module.exports = keyframe_system; ``` -------------------------------- ### G.js Example: Moving Text and Looping Trigger Source: https://g-js-api.github.io/G.js/index This example demonstrates how to configure G.js for exporting to Geometry Dash, create a moving text object, and set up a loop to move the text back and forth. It utilizes functions like `exportConfig`, `unknown_g`, `to_obj`, `with`, `add`, `trigger_function`, `trigger_fn_context`, `move`, `ignore_context_change`, `log.runtime.flash`, and `call`. ```javascript import '@g-js-api/g.js' // configures G.js, so it knows how to export to Geometry Dash // this NEEDS to be ran before anything else GD-related! await $.exportConfig({ type: 'savefile', // you can change this to 'live_editor' if you want to use it using the WSLiveEditor mod, or 'levelstring' if you only want to export the levelstring (make sure to store the result in a variable!) options: { info: true } // displays level info when the program finishes running, check https://g-js-api.github.io/G.js/module-index.html#~save_config for a list of options }); // for a simple example, let's create some moving text // first, store a group in a variable (this is akin to doing 'Next Free' in GD) let my_text = unknown_g(); // now, add some text at X 45 Y 45 with the group ID we defined // GD uses small-step units internally (3x big step), meaning the block is 15 steps from the origin in-game 'Hello, World!' .to_obj() .with(obj_props.X, 45) .with(obj_props.Y, 45) .with(obj_props.GROUPS, my_text) .add(); // let's make a loop that moves this text left and right forever // a 'trigger function' is a system of Geometry Dash triggers let moveloop = trigger_function(() => { let my_context = $.trigger_fn_context(); // stores the ORIGINAL group of the trigger function (it will change later! this is called "context") my_text.move(30, 0, 0.5); // moves the text forwards 30 big step units with a 0.5 move time my_text.move(-30, 0, 0.5); // afterwards, it moves the text BACK 30 big step units to its original place // flashes the background white WITHOUT changing the context of triggers ignore_context_change(() => log.runtime.flash()); // after the two moves, the "context" changes (meaning spawn delays were applied in-between, therefore newer triggers have different group IDs than in the past) // so to loop it, you can just call the group of the original context after all operations are finished my_context.call(); }) // now finally, we can spawn this loop! moveloop.call(); ``` -------------------------------- ### Setup Relative Movement Loop with Collision and Timer (JavaScript) Source: https://g-js-api.github.io/G.js/lib_control-flow.js Initializes a system with collision blocks, a target area, and movement triggers for relative positioning. It sets up collision detection between two blocks (blockA, blockB) which triggers an 'enter_group' function. A timer is also initiated to control the movement loop. ```javascript let rfl_setup = () => { let enter_group = trigger_function(() => {}); let blockA = unknown_b(); let blockB = unknown_b(); let center = unknown_g(); let target = unknown_g(); // collision blocks blockA.collision_block(-135, 135).with(obj_props.SCALING, 0.25).with(obj_props.GROUPS, target).add(); blockB.collision_block(-135, 105).with(obj_props.SCALING, 0.25).with(obj_props.GROUPS, center).with(obj_props.DYNAMIC_BLOCK, true).add(); // center object({ OBJ_ID: 3807, X: -135, Y: 105, GROUPS: center, GROUP_PARENTS: center }).add(); let area = trigger({ OBJ_ID: 3006, AREA_LENGTH: 30000, AREA_MOVE_DIST: -30000, AREA_EASING: 2, AREA_EASING_2: 2, AREA_RELATIVE: true, TARGET: target, CENTER: center, AREA_MOD_FRONT: 1, AREA_MOD_BACK: 1, DIR_BUTTON_INWARDS: 1, DURATION: 0.5, 155: 1, 36: 1, }); area.add(); let move_loop = trigger_function(() => { move_trigger(center, -2400, 0).with(obj_props.SILENT, true).add(); ignore_context_change(() => center.move(2400, 0, 1)); $.trigger_fn_context().call(1); }); let timer_cycle = trigger_function(() => { timer(0, 1, $.trigger_fn_context(), false, false, true, 240).start(); blockA.if_colliding(blockB, enter_group); }); move_loop.call(); timer_cycle.call(); return { enter_group, timer_cycle }; } ``` -------------------------------- ### JavaScript: Render Frame Loop Source: https://g-js-api.github.io/G.js/lib_control-flow.js Sets up a loop that calls a provided function on every render frame. It initializes a setup if not already done and returns a timer cycle that can be used to stop the loop. ```javascript let render_frame_loop = (fn) => { if (!g_setup) g_setup = rfl_setup(); $.extend_trigger_func(g_setup.enter_group, () => { fn.call(); }); return g_setup.timer_cycle; } ``` -------------------------------- ### Live Editor WebSocket Connection and Message Handling (JavaScript) Source: https://g-js-api.github.io/G.js/index.js Establishes a WebSocket connection to the live editor, handles 'open', 'message', and 'error' events. It sends level data in chunks and manages object additions. This functionality requires the WSLiveEditor mod to be installed and the editor to be open in Geode. ```javascript const socket = new WebSocket('ws://127.0.0.1:1313'); warn_lvlstr = false; let lvlString = group_arr($.getLevelString(conf).split(';'), 250).map(x => x.join(';')); socket.addEventListener('message', (event) => { event = JSON.parse(event.data); if (event.status !== "successful") throw new Error(`Live editor failed, ${event.error}: ${event.message}`); }); socket.addEventListener('open', (event) => { socket.send(JSON.stringify({ action: 'REMOVE', group: remove_group, })); // clears extra objects lvlString.forEach((chunk, i) => { setTimeout(() => { socket.send(JSON.stringify({ action: 'ADD', objects: chunk + ';', close: i == lvlString.length - 1 })); }, i * 75); }); }); socket.addEventListener('error', () => { throw new Error(`Connecting to WSLiveEditor failed! Make sure you have installed the WSLiveEditor mod inside of Geode!`); }); ``` -------------------------------- ### Create Particle System - JavaScript Source: https://g-js-api.github.io/G.js/lib_general-purpose.js Creates a particle system with customizable properties. It takes a dictionary of properties and several boolean flags to control its behavior, such as using object color, animating on trigger, and starting quickly. The function returns an object representing the configured particle system. ```javascript let particle_system = (props, use_obj_color = false, animate_on_trigger = false, animate_active_only = false, quick_start = false) => { let datalist = Array(72).fill(0); for (let i in props) { let x = props[i]; if (typeof x == "boolean") x = +x; datalist[all_particles[i]] = x; }; datalist = datalist.join('a'); return object({ OBJ_ID: 2065, PARTICLE_DATA: datalist, USE_OBJ_COLOR: use_obj_color, UNIFORM_OBJ_COLOR: "UNIFORM_OBJ_COLOR" in props ? props.UNIFORM_OBJ_COLOR : false, ANIMATE_ON_TRIGGER: animate_on_trigger, ANIMATE_ACTIVE_ONLY: animate_active_only, QUICK_START: quick_start }); }; ``` -------------------------------- ### Setup Frame Loop for Collision Detection (JavaScript) Source: https://g-js-api.github.io/G.js/lib_control-flow.js Sets up a frame loop that utilizes collision blocks to manage group toggles and trigger functions. It defines two collision blocks (frame_loop1, frame_loop2) and a group (move_g). Collision events between these blocks trigger 'toggle_off' and 'toggle_on' on the move_g, and an empty trigger function. ```javascript let frame_loop_setup = () => { let empty_tfn = trigger_function(_ => {}); let trig_fn = trigger_function(() => { let move_g = unknown_g(); let frame_loop1 = unknown_b(); let frame_loop2 = unknown_b(); // col 1 $.add(object({ OBJ_ID: obj_ids.special.COLLISION_BLOCK, BLOCK_A: frame_loop1, X: -150, Y: 15, DYNAMIC_BLOCK: true })); // col 2 $.add(object({ OBJ_ID: obj_ids.special.COLLISION_BLOCK, BLOCK_A: frame_loop2, X: -150, Y: 50, GROUPS: move_g, DYNAMIC_BLOCK: true })); on(collision(frame_loop1, frame_loop2), trigger_function(() => { move_g.toggle_off(); empty_tfn.call(); })); on(collision_exit(frame_loop1, frame_loop2), trigger_function(() => { move_g.toggle_on(); empty_tfn.call(); })); move_g.move(0, -10); // start loop }); trig_fn.call(); return { trig_fn, empty_tfn }; }; ``` -------------------------------- ### Block Creation Source: https://g-js-api.github.io/G.js/module-block-%24block This section details how to create a new block instance in G.js. ```APIDOC ## new $block ### Description Creates a block from a given number (Block ID). ### Method Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```javascript // Example of creating a block: const myBlock = new $block(123); const specificBlock = new $block(456, true); ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Find Index from Start in Array in JavaScript Source: https://g-js-api.github.io/G.js/index.js This utility function finds the index of a value within an array, starting from a specified index. It returns the index relative to the original array or -1 if the value is not found. ```javascript let indexOfFrom = (array, value, startIndex) => { let newArr = array.slice(startIndex); return newArr.indexOf(value) !== -1 ? newArr.indexOf(value) + (array.length - newArr.length) : -1; } ``` -------------------------------- ### Create and Control Timers in JavaScript Source: https://g-js-api.github.io/G.js/lib_items.js The `timer` function creates a timer object with customizable start and end times, target IDs, and modification options. It allows for starting, stopping, and displaying the timer, with options to ignore timewarps and overrides. Dependencies include `group`, `counter`, and `$.add`. ```javascript let timer = (start_seconds, end_seconds = 0, target_id = group(0), backwards = false, seconds_only = false, stop = true, time_mod = 1, ignore_timewarp = false, no_override = false) => { // START_IME, STOP_TIME, STOP_CHECKED, ITEM, TARGET, TIME_MOD, IGNORE_TIMEWARP, START_PAUSED, DONT_OVERRIDE let c_item = counter(0, false, false, true); let o = { OBJ_ID: 3614, START_TIME: start_seconds, STOP_TIME: end_seconds, STOP_CHECKED: stop, ITEM: c_item.item, TARGET: target_id, TIMER_TIME_MOD: backwards ? -1 : time_mod, IGNORE_TIMEWARP: ignore_timewarp, DONT_OVERRIDE: no_override }; c_item.display = (x, y) => $.add(object({ OBJ_ID: 1615, X: x, Y: y, ITEM: c_item.item, TIME_COUNTER: true, SECONDS_ONLY: seconds_only, COLOR: color(1), })); c_item.set_start = (x) => o.START_TIME = x; c_item.set_end = (x) => o.STOP_TIME = x; c_item.start = () => { $.add(trigger(o)); }; c_item.stop = () => { $.add(trigger({ OBJ_ID: 3617, ITEM: c_item.item, START_STOP: true })) }; return c_item; } ``` -------------------------------- ### Keyframe System Creation Source: https://g-js-api.github.io/G.js/module-keyframes Creates a keyframe system for animating a group of objects. ```APIDOC ## keyframe_system(group) ### Description Creates a keyframe system for a group of objects to animate. ### Method (inner) keyframe_system ### Parameters #### Path Parameters - **group** (group) - Required - Group of objects to animate ### Response #### Success Response (200) - **keyframe_system** (keyframe_system) - The created keyframe system object. ``` -------------------------------- ### Group Methods Source: https://g-js-api.github.io/G.js/module-group-%24group Documentation for various methods available on $group objects, including alpha, animate, call, follow, move, and more. ```APIDOC ## alpha(opacity, duration) ### Description Alpha trigger implementation. ### Method POST ### Endpoint /group/{id}/alpha ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to apply the alpha change to. #### Query Parameters - **opacity** (number) - Optional - Changed opacity. Default is 1. - **duration** (number) - Optional - How long it takes for the opacity to change. Default is 0. ### Request Example ```json { "example": "group.alpha(0.5, 1000)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## animate(anim_idopt) ### Description Animate trigger implementation. ### Method POST ### Endpoint /group/{id}/animate ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to animate. #### Query Parameters - **anim_id** (number) - Optional - Animation ID. Can also use `animations.[monster].[animation name]`. Default is 0. ### Request Example ```json { "example": "group.animate(animations.goblin.attack)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## call(delay) ### Description Calls the group. ### Method POST ### Endpoint /group/{id}/call ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to call. #### Query Parameters - **delay** (number) - Optional - How long to delay the group being called. Default is 0. ### Request Example ```json { "example": "group.call(500)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## follow(other, x_mod, y_mod, duration) ### Description Makes the group follow another group. ### Method POST ### Endpoint /group/{id}/follow ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group that will follow. #### Query Parameters - **other** (group) - Required - The group to follow. - **x_mod** (number) - Optional - How much to speed up/slow down movement on X axis. Default is 1. - **y_mod** (number) - Optional - How much to speed up/slow down movement on Y axis. Default is 1. - **duration** (number) - Optional - How long to follow other group. Default is 999. ### Request Example ```json { "example": "group1.follow(group2, 1.2, 0.8, 2000)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## follow_lerp(groupA, groupB, weight, duration) ### Description Keeps an object's position proportionally between 2 others. ### Method POST ### Endpoint /group/{id}/follow_lerp ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to position. #### Query Parameters - **groupA** (group) - Required - Group of object A to follow. - **groupB** (group) - Required - Group of object B to follow. - **weight** (number) - Optional - How much of the way the group should be kept in. Default is 0.5. - **duration** (number) - Optional - How long to follow. Default is 999. ### Request Example ```json { "example": "group.follow_lerp(groupA, groupB, 0.7, 1500)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## follow_player_y(speedopt, delayopt, offsetopt, max_speedopt, durationopt) ### Description Follows player's Y position. ### Method POST ### Endpoint /group/{id}/follow_player_y ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to follow player Y. #### Query Parameters - **speed** (number) - Optional - How fast group snaps to player Y position. Default is 0. - **delay** (number) - Optional - Delay of movement. Default is 0. - **offset** (number) - Optional - Offset of group. Default is 0. - **max_speed** (number) - Optional - How fast movement of group can be. Default is 0. - **duration** (number) - Optional - How long the group is locked to player Y axis. Default is 0. ### Request Example ```json { "example": "group.follow_player_y(10, 0, 5, 20, 3000)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## lock_to_player(lock_xopt, lock_yopt, durationopt) ### Description Locks group to player's position. ### Method POST ### Endpoint /group/{id}/lock_to_player ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to lock to the player. #### Query Parameters - **lock_x** (boolean) - Optional - Whether to lock to X axis of player. Default is true. - **lock_y** (boolean) - Optional - Whether to lock to Y axis of player. Default is true. - **duration** (number) - Optional - How long group is locked to player. Default is 999. ### Request Example ```json { "example": "group.lock_to_player(true, false, 5000)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## move(x, y, duration, easing, easing_rate, x_multiplier, y_multiplier, multiply) ### Description Moves the group. ### Method POST ### Endpoint /group/{id}/move ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to move. #### Query Parameters - **x** (number) - Required - Movement on X axis. - **y** (number) - Required - Movement on Y axis. - **duration** (number) - Optional - Duration for move trigger. Default is 0. - **easing** (easing) - Optional - How smoothly object moves. - **easing_rate** (number) - Optional - Easing rate for move trigger. Default is 2. - **x_multiplier** (number) - Optional - How much to multiply the amount by on X axis. Default is 1. - **y_multiplier** (number) - Optional - How much to multiply the amount by on Y axis. Default is 1. - **multiply** (boolean) - Optional - Whether to fit the amount of units moved into GD units. Default is true. ### Request Example ```json { "example": "group.move(100, 50, 1000, 'easeOutQuad', 3, 1.5, 1.5, false)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ## move_to(target, duration, x_only, y_only, easing, easing_rate) ### Description Move target implementation. ### Method POST ### Endpoint /group/{id}/move_to ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the group to move. #### Query Parameters - **target** (group) - Required - Group to move to. - **duration** (number) - Optional - How long it takes to move to target. Default is 0. - **x_only** (boolean) - Optional - Whether to only move on X axis. Default is false. - **y_only** (boolean) - Optional - Whether to only move on Y axis. Default is false. - **easing** (easing) - Optional - Easing of movement. - **easing_rate** (number) - Optional - Easing rate of movement. Default is 2. ### Request Example ```json { "example": "group1.move_to(group2, 500, false, false, 'easeInOutCubic', 4)" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ``` -------------------------------- ### Timer Management API Source: https://g-js-api.github.io/G.js/module-items This endpoint manages timer operations. You can set various parameters to control the timer's behavior, such as start and end times, target actions, and modification rules. ```APIDOC ## POST /websites/g-js-api_github_io_g_js ### Description Manages timer operations, allowing configuration of start and end times, target actions, and various timer behaviors. ### Method POST ### Endpoint /websites/g-js-api_github_io_g_js ### Parameters #### Query Parameters - **start_seconds** (number) - Required - Start seconds - **end_seconds** (number) - Optional - `0` - End seconds - **target_id** (group) - Optional - ID to call when timer stops - **backwards** (boolean) - Optional - `false` - Whether to go backwards - **seconds_only** (boolean) - Optional - `false` - Whether to only count seconds - **stop** (boolean) - Optional - `true` - Whether to stop the timer at end_seconds - **time_mod** (number) - Optional - `1` - How much to modify the timer by w/ multiplication (cannot be used if backwards is true) - **ignore_timewarp** (boolean) - Optional - `false` - Whether to ignore timewarp - **no_override** (boolean) - Optional - `false` - Whether to ignore when the timer is overridden by another ### Request Example { "example": "Not applicable, this endpoint uses query parameters." } ### Response #### Success Response (200) - **timer** (any) - Represents the timer status or object. #### Response Example { "example": "{\"remaining\": 10, \"target\": \"some_id\"}" } ``` -------------------------------- ### Particle System API Source: https://g-js-api.github.io/G.js/module-general-purpose Creates a particle system with specified properties and behaviors. ```APIDOC ## POST /api/particle_system ### Description Creates a particle system with customizable properties. This function allows for the addition of visual effects like smoke, sparks, or explosions. ### Method POST ### Endpoint /api/particle_system ### Parameters #### Query Parameters - **props** (dictionary) - Required - A dictionary holding the particle properties. Refer to the "Particles" documentation for details. - **use_obj_color** (boolean) - Optional - Whether to use the object's color for the particle system. Defaults to false. - **animate_on_trigger** (boolean) - Optional - Whether to start the particle system only when the Animate trigger is used. Defaults to false. - **animate_active_only** (boolean) - Optional - Makes `animate_on_trigger` true only if the object is active. Defaults to false. - **quick_start** (boolean) - Optional - Makes normal movement achieved instantly instead of gradually. Defaults to false. ### Response #### Success Response (200) - **Returned particle system** (object) - The trigger object representing the created particle system. ``` -------------------------------- ### Generate Numerical Range (JavaScript) Source: https://g-js-api.github.io/G.js/index.js A utility function to generate an array containing a sequence of numbers. It accepts start, end, and step parameters, supporting both ascending and descending sequences. ```javascript /** * Generates an array holding a sequence of numbers starting at the "start" parameter, ending at the "end" parameter and incrementing by "step" * @param {number} start What number to start at * @param {number} end What number to end at * @param {number} step What number to increment by * @returns {array} Resulting sequence */ function range(start, end, step = 1) { let sw = false; if (start > end) { sw = true; [start, end] = [end, start]; // Swap start and end step = Math.abs(step); // Ensure step is positive } let result = Array.from({ length: Math.ceil((end - start) / step) }, (_, i) => start + i * step); if (sw) result = result.reverse(); return result; }; ``` -------------------------------- ### Control Song Playback and Properties in JavaScript Source: https://g-js-api.github.io/G.js/lib_general-purpose.js Manages song playback in Geometry Dash. It allows preloading, starting, stopping, and editing song properties like volume, speed, and fade effects. The function returns a song object with methods for control. ```javascript let song = (song_id, loop = false, preload = true, channel = 0, volume = 1, speed = 0, start = 0, end = 0, fadein = 0, fadeout = 0) => { if (preload) { let m_obj = { OBJ_ID: 1934, SONG_ID: song_id, SONG_CHANNEL: channel, SONG_VOLUME: volume, SONG_SPEED: speed, SONG_START: start, SONG_END: end, SONG_FADE_IN: fadein, SONG_FADE_OUT: fadeout, SONG_LOOP: loop, PREP: true }; $.add(trigger(m_obj)); let al_load = false; let exp = { start: () => { if (al_load) $.add(trigger(m_obj)); $.add(trigger({ OBJ_ID: 1934, SONG_CHANNEL: channel, LOAD_PREP: true })); if (!al_load) al_load = true; }, edit: (new_volume = volume, new_speed = speed, duration = 0.5, stop = false, stop_loop = false, gid_1 = group(0), gid_2 = group(0), vol_near = 1, vol_med = 0.5, vol_far = 0, min_dist = 0, dist_2 = 0, dist_3 = 0, p1 = false, p2 = false, cam = false, vol_dir = 0) => { $.add(trigger({ OBJ_ID: 3605, DURATION: duration, SONG_CHANNEL: channel, SONG_SPEED: new_speed, SONG_VOLUME: new_volume, SONG_STOP: stop, STOP_LOOP: stop_loop, CHANGE_SPEED: new_speed !== speed, CHANGE_VOLUME: new_volume !== volume, GROUP_ID_1: gid_1, GROUP_ID_2: gid_2, VOL_NEAR: vol_near, VOL_MED: vol_med, VOL_FAR: vol_far, MIN_DIST: min_dist, DIST_2: dist_2, DIST_3: dist_3, P1: p1, P2: p2, CAM: cam, VOLUME_DIRECTION: vol_dir })); }, stop: () => { exp.edit(volume, speed, 0.5, true, true); } }; return exp; } $.add(trigger({ ``` -------------------------------- ### Options Trigger API Source: https://g-js-api.github.io/G.js/module-general-purpose Implements the options trigger for game settings. ```APIDOC ## POST /api/options ### Description Implements the options trigger, which is used to control various game settings and configurations. ### Method POST ### Endpoint /api/options ### Response #### Success Response (200) - **Options trigger** (options) - The trigger object representing the options settings. ``` -------------------------------- ### gamescene Input Control Abstraction Source: https://g-js-api.github.io/G.js/lib_events.js This function sets up a gamescene with various interactive elements and input controls. It configures groups, portals, blocks, and collision detection, returning an object with methods for handling button presses and releases. ```javascript let gamescene = () => { // Triggers and groups follow_x_group = unknown_g(); follow_y_group = unknown_g(); hidden_group = unknown_g(); hidden_group.alpha(0); follow_x_group.lock_to_player((lock_x = true), (lock_y = false)); follow_x_group.move((x = 0), (y = 5), (duration = 0.01)); follow_y_group.follow_player_y(); hide_player(); // Portals $.add(object({ OBJ_ID: obj_ids.portals.DUAL_ON, X: 0, Y: 30, GROUPS: hidden_group, })); $.add(object({ OBJ_ID: obj_ids.portals.WAVE, X: 0, Y: 30, GROUPS: hidden_group, })); $.add(({ OBJ_ID: obj_ids.portals.SIZE_MINI, X: 0, Y: 30, GROUPS: hidden_group, })); // Top and bottom blocks $.add(({ OBJ_ID: 1, X: 0, Y: 33, GROUPS: [hidden_group, follow_x_group], })); $.add(object({ OBJ_ID: 1, X: 0, Y: -12, GROUPS: [hidden_group, follow_x_group], })); // Collision blocks player_block = unknown_b(); collide_block = unknown_b(); $.add(object({ OBJ_ID: obj_ids.special.COLLISION_BLOCK, DYNAMIC_BLOCK: true, BLOCK_A: player_block, X: 0, Y: 0, GROUPS: [hidden_group, follow_x_group, follow_y_group], })); $.add(({ OBJ_ID: obj_ids.special.COLLISION_BLOCK, DYNAMIC_BLOCK: false, BLOCK_A: collide_block, X: 0, Y: 37, GROUPS: [hidden_group, follow_x_group], })); // D block $.add(({ OBJ_ID: obj_ids.special.D_BLOCK, SCALING: 2, X: 0, Y: 15, GROUPS: [hidden_group, follow_x_group], })); return { button_a: () => { return collision(player_block, collide_block); }, button_b: () => { return touch(true); }, button_a_end: () => { return collision_exit(player_block, collide_block); }, button_b_end: () => { return touch_end(true); }, hidden_group: hidden_group, }; }; ``` -------------------------------- ### Constructor: $group Source: https://g-js-api.github.io/G.js/module-group-%24group Creates a new group with a specified ID and optional specific flag. ```APIDOC ## new $group(number, specificopt) ### Description Creates a group from a number. ### Method Constructor ### Parameters #### Path Parameters - **number** (number) - Required - Group ID - **specific** (boolean) - Optional - Whether to disallow G.js from using that specific group again ### Request Example ```json { "example": "new group(100, true)" } ``` ### Response #### Success Response (200) - **Group** (object) - The newly created group instance. #### Response Example ```json { "example": "// Returns a group object" } ``` ``` -------------------------------- ### Get Level Objects by Property and Pattern JavaScript Source: https://g-js-api.github.io/G.js/index.js Retrieves objects from the level data that match a specific property and a pattern function. It first parses the raw level string into objects using `levelstring_to_obj`. The property can be specified by its key or its mapped name from `d`. Dependencies include `levelstring_to_obj`, `this.raw_levelstring`, and `d`. ```javascript get_objects: function (prop, pattern) { let level_arr = levelstring_to_obj(this.raw_levelstring); return level_arr.filter(o => { let cond_1 = prop in o || d[prop] in o, cond_2; if (cond_1) cond_2 = pattern(o[prop] || o[d[prop]]); return cond_1 && cond_2; }); } ``` -------------------------------- ### Shader Layers Source: https://g-js-api.github.io/G.js/module-shaders Provides a dictionary abstracting all shader layers into readable values. ```APIDOC ## shader_layers :shader_layers ### Description Dictionary abstracting all shader layers into readable values. ### Type shader_layers ``` -------------------------------- ### Timer Source: https://g-js-api.github.io/G.js/module-items Implementation of timers, allowing for the creation and management of timed events. ```APIDOC ## timer ### Description Implementation of timers. Allows for the creation and management of timed events. ### Method (inner) ### Endpoint N/A (This appears to be an internal function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "start_seconds": 0, "end_seconds": 60, "target_id": "target_event_id", "backwards": false, "seconds_only": true, "stop": false, "time_mod": 1, "ignore_timewarp": false, "no_override": false } ``` ### Response #### Success Response (200) - **{timer}** - A timer object representing the created timer. #### Response Example ```json { "timer_id": "unique_timer_id", "remaining_seconds": 60 } ``` ``` -------------------------------- ### Listen to frame update events Source: https://g-js-api.github.io/G.js/lib_events.js The 'frame' and 'render_frame' functions create event listeners that trigger on every game frame and render frame, respectively. They wrap a callback function to be executed by internal frame loop functions. ```javascript let frame = () => { return { event: (tf) => frame_loop(tf) } }; let render_frame = () => { return { event: (tf) => render_frame_loop(tf) } }; ``` -------------------------------- ### Execute Function Every Render Frame (JavaScript) Source: https://g-js-api.github.io/G.js/lib_control-flow.js Creates a loop that executes a provided trigger function on every render frame. It initializes the frame loop setup if not already done and extends the empty trigger function to call the provided function. Returns a trigger function that can be used to stop the loop. ```javascript let frame_loop = (tfn) => { if (!fl_setup) fl_setup = frame_loop_setup(); $.extend_trigger_func(fl_setup.empty_tfn, () => { tfn.call(); }); return fl_setup.trig_fn; }; ``` -------------------------------- ### Create Counter Source: https://g-js-api.github.io/G.js/lib_counter.js Initializes a new counter object. ```APIDOC ## Create Counter ### Description Creates a new counter object. The counter can be initialized with a number or a boolean value, defaulting to 0 if no argument is provided. ### Method `counter(num)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **`num`** (number|boolean) - Optional - Number or boolean to be represented by the counter. Defaults to 0. ### Request Example ```javascript // Initialize a counter with a value of 10 const myCounter = counter(10); // Initialize a counter with a boolean value (true might represent 1, false 0) const booleanCounter = counter(true); // Initialize a counter with the default value of 0 const defaultCounter = counter(); ``` ### Response #### Success Response (200) - **`counter`** (object) - The newly created counter object with its associated methods. #### Response Example ```json { "counter": { "item": "generated_item_id", "type": "counter_type", "add": function() { /* ... */ }, "subtract": function() { /* ... */ }, "multiply": function() { /* ... */ }, "divide": function() { /* ... */ }, "set": function() { /* ... */ }, "reset": function() { /* ... */ }, "if_is": function() { /* ... */ }, "to_const": function() { /* ... */ }, "copy_to": function() { /* ... */ }, "display": function() { /* ... */ }, "to_obj": function() { /* ... */ }, "add_to": function() { /* ... */ }, "subtract_from": function() { /* ... */ }, "abs": function() { /* ... */ }, "neg": function() { /* ... */ }, "bits": 32 } } ``` ``` -------------------------------- ### Get Level String in G.js (Deprecated) Source: https://g-js-api.github.io/G.js/index.js This JavaScript function retrieves the level string representation of data. It includes a deprecation warning and checks group count against a limit, throwing an error if exceeded. Optional 'info' parameter logs statistics. It depends on `prep_lvl` and global variables like `unavailable_g`, `limit`, `resulting`, `unavailable_c`. ```javascript let getLevelString = (options = {}) => { if (warn_lvlstr) process.emitWarning('Using $.getLevelString is deprecated and will be removed in the future.', { type: 'DeprecationWarning', detail: `Migrate by using `await $.exportConfig({ type: 'levelstring', options: })`. Note that instead of using $.exportConfig at the end of the program, use it at the top, below the G.js import but above all other code.` }); prep_lvl(); if (unavailable_g <= limit) { if (options.info) { console.log('Finished, result stats:'); console.log('Object count:', resulting.split(';').length - 1); console.log('Group count:', unavailable_g - 1); console.log('Color count:', unavailable_c); } } else { if ( (options.hasOwnProperty('group_count_warning') && options.group_count_warning == true) || !options.hasOwnProperty('group_count_warning') ) throw new Error(`Group count surpasses the limit! (${unavailable_g}/${limit})`); } return resulting; }; ``` -------------------------------- ### Listen to a generic event Source: https://g-js-api.github.io/G.js/lib_events.js The 'on' function allows you to attach a callback to a specific event. This is a general-purpose event listener. It takes an event object and a callback function as arguments. ```javascript let on = (event, callback) => { event.event(callback); }; ``` -------------------------------- ### JavaScript: Initialize Global Context Source: https://g-js-api.github.io/G.js/index.js Initializes the 'global' context by adding it to the list of all contexts. This ensures that a default context is available upon application startup. ```javascript Context.add(new Context("global")) ``` -------------------------------- ### Counter Creation API Source: https://g-js-api.github.io/G.js/module-counter This section details the methods for creating counter objects. ```APIDOC ## POST /counter ### Description Creates a counter object with optional parameters to customize its behavior. ### Method POST ### Endpoint /counter ### Parameters #### Query Parameters - **num** (number) - Optional - Number or boolean to be represented by the counter. - **use_id** (boolean) - Optional - Whether to use an existing item ID as a counter instead of creating a new item. Defaults to `false`. - **persistent** (boolean) - Optional - Whether to make the counter persistent between attempts. Defaults to `false`. - **timer** (boolean) - Optional - Whether to make the counter a timer. Defaults to `false`. ### Response #### Success Response (200) - **counter** (object) - The created counter object. ### Response Example { "counter": { "item": "item_id_123", "type": "counter_type", "add": "function", "subtract": "function", "multiply": "function", "divide": "function", "set": "function", "reset": "function", "if_is": "function", "to_const": "function", "copy_to": "function", "display": "function", "to_obj": "function", "add_to": "function", "subtract_from": "function", "abs": "function", "neg": "function", "bits": "number" } } ``` ```APIDOC ## POST /float_counter ### Description Creates a floating-point counter object. ### Method POST ### Endpoint /float_counter ### Parameters #### Query Parameters - **num** (number) - Optional - Number or boolean to be represented by the counter. Defaults to `0`. ### Response #### Success Response (200) - **counter** (object) - The created floating-point counter object. ### Response Example { "counter": { "item": "item_id_456", "type": "float_counter_type", "add": "function", "subtract": "function", "multiply": "function", "divide": "function", "set": "function", "reset": "function", "if_is": "function", "to_const": "function", "copy_to": "function", "display": "function", "to_obj": "function", "add_to": "function", "subtract_from": "function", "abs": "function", "neg": "function", "bits": "number" } } ```