From 9bd3cb6ce32a89508a533574456924ece059d69d Mon Sep 17 00:00:00 2001 From: SKPG-Tech <42890752+SKPG-Tech@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:31:11 +0200 Subject: [PATCH] Substantial documentation refactor --- blog/2024-03-20-first-blog-post.md | 2 +- .../manifest-files.md | 0 .../mesh-files.md | 2 +- .../sound-files.md | 0 docs/{lua-guides => Guides/Lua}/advanced.md | 0 docs/{lua-guides => Guides/Lua}/beginner.md | 0 .../Lua}/intermediate.md | 0 .../Other}/60-fps-animation.mdx | 0 docs/api/Fmath.md | 112 ++ docs/api/{pewpew-library.md => PewPew.md} | 1011 ++++++++++++++--- docs/api/_category_.json | 8 - docs/api/fmath-library.md | 44 - docs/api/types.mdx | 3 +- docs/file-information/_category_.json | 8 - docs/intro.md | 18 +- docs/lua-guides/_category_.json | 8 - docs/other-guides/_category_.json | 8 - docs/other/_category_.json | 8 - docusaurus.config.ts | 45 +- sidebars.ts | 28 +- src/components/fx-converter.tsx | 35 +- src/css/custom.css | 2 +- src/pages/markdown-page.md | 7 - 23 files changed, 1014 insertions(+), 335 deletions(-) rename docs/{file-information => File Information}/manifest-files.md (100%) rename docs/{file-information => File Information}/mesh-files.md (98%) rename docs/{file-information => File Information}/sound-files.md (100%) rename docs/{lua-guides => Guides/Lua}/advanced.md (100%) rename docs/{lua-guides => Guides/Lua}/beginner.md (100%) rename docs/{lua-guides => Guides/Lua}/intermediate.md (100%) rename docs/{other-guides => Guides/Other}/60-fps-animation.mdx (100%) create mode 100644 docs/api/Fmath.md rename docs/api/{pewpew-library.md => PewPew.md} (52%) delete mode 100644 docs/api/_category_.json delete mode 100644 docs/api/fmath-library.md delete mode 100644 docs/file-information/_category_.json delete mode 100644 docs/lua-guides/_category_.json delete mode 100644 docs/other-guides/_category_.json delete mode 100644 docs/other/_category_.json delete mode 100644 src/pages/markdown-page.md diff --git a/blog/2024-03-20-first-blog-post.md b/blog/2024-03-20-first-blog-post.md index 39701b8..ebc3996 100644 --- a/blog/2024-03-20-first-blog-post.md +++ b/blog/2024-03-20-first-blog-post.md @@ -5,7 +5,7 @@ authors: tastykiwi tags: [first] --- -Welcome to the first blog article! We are so excited to move the entirety of PPL level development documentation here. This platform allows us to make more interactive (via React components), good looking documentation and having powerful search powered by Algolia! +Welcome to the first blog article! We are so excited to move the entirety of PPL level development documentation here. This platform allows us to make more interactive (via React components), good looking documentation and having powerful search! I hope you'll like the new home for PewPew docs. diff --git a/docs/file-information/manifest-files.md b/docs/File Information/manifest-files.md similarity index 100% rename from docs/file-information/manifest-files.md rename to docs/File Information/manifest-files.md diff --git a/docs/file-information/mesh-files.md b/docs/File Information/mesh-files.md similarity index 98% rename from docs/file-information/mesh-files.md rename to docs/File Information/mesh-files.md index 21d5fdd..05132ab 100644 --- a/docs/file-information/mesh-files.md +++ b/docs/File Information/mesh-files.md @@ -47,6 +47,6 @@ The _optional_ `colors` field contains the colors of each vertexes. If the `colo Note that all meshes are rendered with additive blending. -# Procedural rendering +## Procedural rendering Astute readers may have realized that because `meshes` is described in a Lua script, it can be generated at runtime. See for instance this [example](https://github.com/jyaif/ppl-utils/blob/d32dbec8a171c9bcc0f800dcd864f175c42c34fd/content/levels/advanced_graphics/polar_graphic.lua#L36). diff --git a/docs/file-information/sound-files.md b/docs/File Information/sound-files.md similarity index 100% rename from docs/file-information/sound-files.md rename to docs/File Information/sound-files.md diff --git a/docs/lua-guides/advanced.md b/docs/Guides/Lua/advanced.md similarity index 100% rename from docs/lua-guides/advanced.md rename to docs/Guides/Lua/advanced.md diff --git a/docs/lua-guides/beginner.md b/docs/Guides/Lua/beginner.md similarity index 100% rename from docs/lua-guides/beginner.md rename to docs/Guides/Lua/beginner.md diff --git a/docs/lua-guides/intermediate.md b/docs/Guides/Lua/intermediate.md similarity index 100% rename from docs/lua-guides/intermediate.md rename to docs/Guides/Lua/intermediate.md diff --git a/docs/other-guides/60-fps-animation.mdx b/docs/Guides/Other/60-fps-animation.mdx similarity index 100% rename from docs/other-guides/60-fps-animation.mdx rename to docs/Guides/Other/60-fps-animation.mdx diff --git a/docs/api/Fmath.md b/docs/api/Fmath.md new file mode 100644 index 0000000..4f3cf2b --- /dev/null +++ b/docs/api/Fmath.md @@ -0,0 +1,112 @@ +--- +sidebar_position: 3 +--- + + + +# fmath library + +`fmath` contains a set of mathematical functions that work with FixedPoint numbers and integers. `fmath` replaces Lua's `math` library in game scripts (you can use Lua's `math` library outside of game scripts). + +[//]: # "This file is automatically generated." +[//]: # "Manual edits will be overwritten." + +## Functions +### `max_fixedpoint()` +```tsx +fmath.max_fixedpoint(): FixedPoint +``` +Returns the maximum value a fixedpoint integer can take. + + +--- +### `random_fixedpoint()` +```tsx +fmath.random_fixedpoint( + min: FixedPoint, + max: FixedPoint +): FixedPoint +``` +Returns a random fixedpoint value in the range [`min`, `max`]. `max` must be greater or equal to `min`. + + +--- +### `random_int()` +```tsx +fmath.random_int( + min: int, + max: int +): int +``` +Returns an integer in the range [`min`, `max`]. `max` must be greater or equal to `min`. + + +--- +### `sqrt()` +```tsx +fmath.sqrt(x: FixedPoint): FixedPoint +``` +Returns the square root of `x`. `x` must be greater or equal to 0. + + +--- +### `from_fraction()` +```tsx +fmath.from_fraction( + numerator: int, + denominator: int +): FixedPoint +``` +Returns the fixedpoint value representing the fraction `numerator`/`denominator`. `denominator` must not be equal to zero. + + +--- +### `to_int()` +```tsx +fmath.to_int(value: FixedPoint): int +``` +Returns the integral part of the `value`. + + +--- +### `abs_fixedpoint()` +```tsx +fmath.abs_fixedpoint(value: FixedPoint): FixedPoint +``` +Returns the absolute value. + + +--- +### `to_fixedpoint()` +```tsx +fmath.to_fixedpoint(value: int): FixedPoint +``` +Returns a fixedpoint value with the integral part of `value`, and no fractional part. + + +--- +### `sincos()` +```tsx +fmath.sincos(angle: FixedPoint): FixedPoint, FixedPoint +``` +Returns the sinus and cosinus of `angle`. `angle` is in radian. + + +--- +### `atan2()` +```tsx +fmath.atan2( + y: FixedPoint, + x: FixedPoint +): FixedPoint +``` +Returns the principal value of the arc tangent of y/x. Returns a value in the range [0, 2π[. + + +--- +### `tau()` +```tsx +fmath.tau(): FixedPoint +``` +Returns τ (aka 2π). + diff --git a/docs/api/pewpew-library.md b/docs/api/PewPew.md similarity index 52% rename from docs/api/pewpew-library.md rename to docs/api/PewPew.md index 2955091..66245e3 100644 --- a/docs/api/pewpew-library.md +++ b/docs/api/PewPew.md @@ -2,90 +2,16 @@ sidebar_position: 2 --- + + # pewpew library +The `pewpew` library contains all the functions for configuring levels and managing entities. + [//]: # "This file is automatically generated." [//]: # "Manual edits will be overwritten." -The `pewpew` library contains all the functions for configuring levels and managing entities. -* [print(str)](#void-printstring-str-) -* [print_debug_info()](#void-print_debug_info) -* [set_level_size(width, height)](#void-set_level_sizefixedpoint-width--fixedpoint-height-) -* [add_wall(start_x, start_y, end_x, end_y)](#int-add_wallfixedpoint-start_x--fixedpoint-start_y--fixedpoint-end_x--fixedpoint-end_y-) -* [remove_wall(wall_id)](#void-remove_wallint-wall_id-) -* [add_update_callback(update_callback)](#void-add_update_callbackcallback-update_callback-) -* [get_number_of_players()](#int-get_number_of_players) -* [increase_score_of_player(player_index, delta)](#void-increase_score_of_playerint-player_index--int-delta-) -* [increase_score_streak_of_player(player_index, delta)](#void-increase_score_streak_of_playerint-player_index--int-delta-) -* [get_score_streak_level(player_index)](#int-get_score_streak_levelint-player_index-) -* [stop_game()](#void-stop_game) -* [get_player_inputs(player_index)](#fixedpoint-fixedpoint-fixedpoint-fixedpoint-get_player_inputsint-player_index-) -* [get_score_of_player(player_index)](#int-get_score_of_playerint-player_index-) -* [configure_player(player_index, configuration)](#void-configure_playerint-player_index--map-boolean-has_lost--int-shield--fixedpoint-camera_x_override--fixedpoint-camera_y_override--fixedpoint-camera_distance--fixedpoint-camera_rotation_x_axis--int-move_joystick_color--int-shoot_joystick_color-configuration-) -* [configure_player_hud(player_index, configuration)](#void-configure_player_hudint-player_index--map-string-top_left_line-configuration-) -* [get_player_configuration(player_index)](#map-int-shield--boolean-has_lost-get_player_configurationint-player_index-) -* [configure_player_ship_weapon(ship_id, configuration)](#void-configure_player_ship_weaponentityid-ship_id--map-int-frequency--int-cannon--int-duration-configuration-) -* [add_damage_to_player_ship(ship_id, damage)](#void-add_damage_to_player_shipentityid-ship_id--int-damage-) -* [add_arrow_to_player_ship(ship_id, target_id, color)](#int-add_arrow_to_player_shipentityid-ship_id--entityid-target_id--int-color-) -* [remove_arrow_from_player_ship(ship_id, arrow_id)](#void-remove_arrow_from_player_shipentityid-ship_id--int-arrow_id-) -* [make_player_ship_transparent(ship_id, transparency_duration)](#void-make_player_ship_transparententityid-ship_id--int-transparency_duration-) -* [set_player_ship_speed(ship_id, factor, offset, duration)](#fixedpoint-set_player_ship_speedentityid-ship_id--fixedpoint-factor--fixedpoint-offset--int-duration-) -* [get_all_entities()](#list-entityid-get_all_entities) -* [get_entities_colliding_with_disk(center_x, center_y, radius)](#list-entityid-get_entities_colliding_with_diskfixedpoint-center_x--fixedpoint-center_y--fixedpoint-radius-) -* [get_entity_count(type)](#int-get_entity_countint-type-) -* [get_entity_type(entity_id)](#int-get_entity_typeentityid-entity_id-) -* [play_ambient_sound(sound_path, index)](#void-play_ambient_soundstring-sound_path--int-index-) -* [play_sound(sound_path, index, x, y)](#void-play_soundstring-sound_path--int-index--fixedpoint-x--fixedpoint-y-) -* [create_explosion(x, y, color, scale, particle_count)](#void-create_explosionfixedpoint-x--fixedpoint-y--int-color--fixedpoint-scale--int-particle_count-) -* [new_asteroid(x, y)](#entityid-new_asteroidfixedpoint-x--fixedpoint-y-) -* [new_asteroid_with_size(x, y, size)](#entityid-new_asteroid_with_sizefixedpoint-x--fixedpoint-y--int-size-) -* [new_baf(x, y, angle, speed, lifetime)](#entityid-new_baffixedpoint-x--fixedpoint-y--fixedpoint-angle--fixedpoint-speed--int-lifetime-) -* [new_baf_red(x, y, angle, speed, lifetime)](#entityid-new_baf_redfixedpoint-x--fixedpoint-y--fixedpoint-angle--fixedpoint-speed--int-lifetime-) -* [new_baf_blue(x, y, angle, speed, lifetime)](#entityid-new_baf_bluefixedpoint-x--fixedpoint-y--fixedpoint-angle--fixedpoint-speed--int-lifetime-) -* [new_bomb(x, y, type)](#entityid-new_bombfixedpoint-x--fixedpoint-y--int-type-) -* [new_bonus(x, y, type, config)](#entityid-new_bonusfixedpoint-x--fixedpoint-y--int-type--map-int-box_duration--int-cannon--int-frequency--int-weapon_duration--int-number_of_shields--fixedpoint-speed_factor--fixedpoint-speed_offset--int-speed_duration--callback-taken_callback-config-) -* [new_crowder(x, y)](#entityid-new_crowderfixedpoint-x--fixedpoint-y-) -* [new_floating_message(x, y, str, config)](#entityid-new_floating_messagefixedpoint-x--fixedpoint-y--string-str--map-fixedpoint-scale--int-ticks_before_fade--boolean-is_optional-config-) -* [new_customizable_entity(x, y)](#entityid-new_customizable_entityfixedpoint-x--fixedpoint-y-) -* [new_inertiac(x, y, acceleration, angle)](#entityid-new_inertiacfixedpoint-x--fixedpoint-y--fixedpoint-acceleration--fixedpoint-angle-) -* [new_mothership(x, y, type, angle)](#entityid-new_mothershipfixedpoint-x--fixedpoint-y--int-type--fixedpoint-angle-) -* [new_pointonium(x, y, value)](#entityid-new_pointoniumfixedpoint-x--fixedpoint-y--int-value-) -* [new_player_ship(x, y, player_index)](#entityid-new_player_shipfixedpoint-x--fixedpoint-y--int-player_index-) -* [new_player_bullet(x, y, angle, player_index)](#entityid-new_player_bulletfixedpoint-x--fixedpoint-y--fixedpoint-angle--int-player_index-) -* [new_rolling_cube(x, y)](#entityid-new_rolling_cubefixedpoint-x--fixedpoint-y-) -* [new_rolling_sphere(x, y, angle, speed)](#entityid-new_rolling_spherefixedpoint-x--fixedpoint-y--fixedpoint-angle--fixedpoint-speed-) -* [new_wary(x, y)](#entityid-new_waryfixedpoint-x--fixedpoint-y-) -* [new_ufo(x, y, dx)](#entityid-new_ufofixedpoint-x--fixedpoint-y--fixedpoint-dx-) -* [rolling_cube_set_enable_collisions_with_walls(entity_id, collide_with_walls)](#void-rolling_cube_set_enable_collisions_with_wallsentityid-entity_id--boolean-collide_with_walls-) -* [ufo_set_enable_collisions_with_walls(entity_id, collide_with_walls)](#void-ufo_set_enable_collisions_with_wallsentityid-entity_id--boolean-collide_with_walls-) -* [entity_get_position(entity_id)](#fixedpoint-fixedpoint-entity_get_positionentityid-entity_id-) -* [entity_get_is_alive(entity_id)](#boolean-entity_get_is_aliveentityid-entity_id-) -* [entity_get_is_started_to_be_destroyed(entity_id)](#boolean-entity_get_is_started_to_be_destroyedentityid-entity_id-) -* [entity_set_position(entity_id, x, y)](#void-entity_set_positionentityid-entity_id--fixedpoint-x--fixedpoint-y-) -* [entity_set_radius(entity_id, radius)](#void-entity_set_radiusentityid-entity_id--fixedpoint-radius-) -* [entity_set_update_callback(entity_id, callback)](#void-entity_set_update_callbackentityid-entity_id--callback-callback-) -* [entity_destroy(entity_id)](#void-entity_destroyentityid-entity_id-) -* [entity_react_to_weapon(entity_id, weapon)](#boolean-entity_react_to_weaponentityid-entity_id--map-int-type--fixedpoint-x--fixedpoint-y--int-player_index-weapon-) -* [customizable_entity_set_position_interpolation(entity_id, enable)](#void-customizable_entity_set_position_interpolationentityid-entity_id--boolean-enable-) -* [customizable_entity_set_mesh(entity_id, file_path, index)](#void-customizable_entity_set_meshentityid-entity_id--string-file_path--int-index-) -* [customizable_entity_set_flipping_meshes(entity_id, file_path, index_0, index_1)](#void-customizable_entity_set_flipping_meshesentityid-entity_id--string-file_path--int-index_0--int-index_1-) -* [customizable_entity_set_mesh_color(entity_id, color)](#void-customizable_entity_set_mesh_colorentityid-entity_id--int-color-) -* [customizable_entity_set_string(entity_id, text)](#void-customizable_entity_set_stringentityid-entity_id--string-text-) -* [customizable_entity_set_mesh_xyz(entity_id, x, y, z)](#void-customizable_entity_set_mesh_xyzentityid-entity_id--fixedpoint-x--fixedpoint-y--fixedpoint-z-) -* [customizable_entity_set_mesh_z(entity_id, z)](#void-customizable_entity_set_mesh_zentityid-entity_id--fixedpoint-z-) -* [customizable_entity_set_mesh_scale(entity_id, scale)](#void-customizable_entity_set_mesh_scaleentityid-entity_id--fixedpoint-scale-) -* [customizable_entity_set_mesh_xyz_scale(entity_id, x_scale, y_scale, z_scale)](#void-customizable_entity_set_mesh_xyz_scaleentityid-entity_id--fixedpoint-x_scale--fixedpoint-y_scale--fixedpoint-z_scale-) -* [customizable_entity_set_mesh_angle(entity_id, angle, x_axis, y_axis, z_axis)](#void-customizable_entity_set_mesh_angleentityid-entity_id--fixedpoint-angle--fixedpoint-x_axis--fixedpoint-y_axis--fixedpoint-z_axis-) -* [customizable_entity_skip_mesh_attributes_interpolation(entity_id)](#void-customizable_entity_skip_mesh_attributes_interpolationentityid-entity_id-) -* [customizable_entity_configure_music_response(entity_id, config)](#void-customizable_entity_configure_music_responseentityid-entity_id--map-int-color_start--int-color_end--fixedpoint-scale_x_start--fixedpoint-scale_x_end--fixedpoint-scale_y_start--fixedpoint-scale_y_end--fixedpoint-scale_z_start--fixedpoint-scale_z_end-config-) -* [customizable_entity_add_rotation_to_mesh(entity_id, angle, x_axis, y_axis, z_axis)](#void-customizable_entity_add_rotation_to_meshentityid-entity_id--fixedpoint-angle--fixedpoint-x_axis--fixedpoint-y_axis--fixedpoint-z_axis-) -* [customizable_entity_set_visibility_radius(entity_id, radius)](#void-customizable_entity_set_visibility_radiusentityid-entity_id--fixedpoint-radius-) -* [customizable_entity_configure_wall_collision(entity_id, collide_with_walls, collision_callback)](#void-customizable_entity_configure_wall_collisionentityid-entity_id--boolean-collide_with_walls--callback-collision_callback-) -* [customizable_entity_set_player_collision_callback(entity_id, collision_callback)](#void-customizable_entity_set_player_collision_callbackentityid-entity_id--callback-collision_callback-) -* [customizable_entity_set_weapon_collision_callback(entity_id, weapon_collision_callback)](#void-customizable_entity_set_weapon_collision_callbackentityid-entity_id--callback-weapon_collision_callback-) -* [customizable_entity_start_spawning(entity_id, spawning_duration)](#void-customizable_entity_start_spawningentityid-entity_id--int-spawning_duration-) -* [customizable_entity_start_exploding(entity_id, explosion_duration)](#void-customizable_entity_start_explodingentityid-entity_id--int-explosion_duration-) -## enums +## Enums ### EntityType * ASTEROID * BAF @@ -156,39 +82,87 @@ The `pewpew` library contains all the functions for configuring levels and manag * MEDIUM * LARGE * VERY_LARGE -## functions -### _void_ print(_String_ `str` ) +## Functions +### `print()` +```tsx +pewpew.print(str: string) +``` Prints `str` in the console for debugging. + +> Example: > ```lua > local some_number = 42 > pewpew.print("the value of some_number is: " .. some_number) > ``` -### _void_ print_debug_info() + +--- +### `print_debug_info()` +```tsx +pewpew.print_debug_info() +``` Prints debug info: the number of entities created and the amount of memory used by the script. + +> Example: > ```lua > pewpew.print_debug_info() > ``` -### _void_ set_level_size(_FixedPoint_ `width` , _FixedPoint_ `height` ) + +--- +### `set_level_size()` +```tsx +pewpew.set_level_size( + width: FixedPoint, + height: FixedPoint +) +``` Sets the level's size. Implicetely adds walls to make sure that entities can not go outside of the level's boundaries. `width` and `height` are clamped to the range ]0fx, 6000fx]. If this function is not called, the level size is (10fx, 10fx), which is uselessly small for most cases. + +> Example: > ```lua > local width = 300fx > local height = 200fx > pewpew.set_level_size(width, height) > ``` -### _int_ add_wall(_FixedPoint_ `start_x` , _FixedPoint_ `start_y` , _FixedPoint_ `end_x` , _FixedPoint_ `end_y` ) + +--- +### `add_wall()` +```tsx +pewpew.add_wall( + start_x: FixedPoint, + start_y: FixedPoint, + end_x: FixedPoint, + end_y: FixedPoint +): int +``` Adds a wall to the level from (`start_x`,`start_y`) to (`end_x`,`end_y`), and returns its wall ID. A maximum of 200 walls can be added to a level. + +> Example: > ```lua > pewpew.add_wall(100fx, 100fx, 200fx, 200fx) > ``` -### _void_ remove_wall(_int_ `wall_id` ) + +--- +### `remove_wall()` +```tsx +pewpew.remove_wall(wall_id: int) +``` Remove the wall with the given `wall_id`. + +> Example: > ```lua > local wall_id = pewpew.add_wall(100fx, 100fx, 200fx, 200fx) > -- Later, when the wall needs to be removed: > pewpew.remove_wall(wall_id) > ``` -### _void_ add_update_callback(_Callback_ `update_callback` ) + +--- +### `add_update_callback()` +```tsx +pewpew.add_update_callback(update_callback: function) +``` Adds a callback that will be updated at each game tick. + +> Example: > ```lua > local tick_count = 0 > pewpew.add_update_callback(function() @@ -196,180 +170,682 @@ Adds a callback that will be updated at each game tick. > tick_count = tick_count + 1 > end) > ``` -### _int_ get_number_of_players() + +--- +### `get_number_of_players()` +```tsx +pewpew.get_number_of_players(): int +``` Returns the number of players in the game. -### _void_ increase_score_of_player(_int_ `player_index` , _int_ `delta` ) + + +--- +### `increase_score_of_player()` +```tsx +pewpew.increase_score_of_player( + player_index: int, + delta: int +) +``` Increases the score of the player at the specified `player_index` by an amount of `delta`. `player_index` must in the range [0, get_number_of_players() - 1]. Note that `delta` can be negative. -### _void_ increase_score_streak_of_player(_int_ `player_index` , _int_ `delta` ) + + +--- +### `increase_score_streak_of_player()` +```tsx +pewpew.increase_score_streak_of_player( + player_index: int, + delta: int +) +``` Increases the score streak counter of the player at the specified `player_index` by an amount of `delta`. This counter is used to determine at which level of score streak the player is at. In turn, the score streak level is used to determine how much pointonium is given. Typically the score streak counter should be increased when an enemy is destroyed with the same score that the enemy provide. `player_index` must in the range [0, get_number_of_players() - 1]. Note that `delta` can be negative. -### _int_ get_score_streak_level(_int_ `player_index` ) + + +--- +### `get_score_streak_level()` +```tsx +pewpew.get_score_streak_level(player_index: int): int +``` Returns a number between 0 and 3. 0 is the lowest score streak (no pointonium is given), while 3 is the highest (3 pointoniums is usually given) -### _void_ stop_game() + + +--- +### `stop_game()` +```tsx +pewpew.stop_game() +``` Ends the current game. -### _FixedPoint_, _FixedPoint_, _FixedPoint_, _FixedPoint_ get_player_inputs(_int_ `player_index` ) + + +--- +### `get_player_inputs()` +```tsx +pewpew.get_player_inputs(player_index: int): FixedPoint, FixedPoint, FixedPoint, FixedPoint +``` Returns the inputs of the player at the specified `index`. The return values are in order: the movement joystick's angle (between 0 and 2pi), the movement joystick's distance (between 0 and 1), the shoot joystick's angle (between 0 and 2pi), and the shoot joystick's distance (between 0 and 1). + +> Example: > ```lua > local move_angle, move_distance, shoot_angle, shoot_distance = pewpew.get_player_inputs(0) > ``` -### _int_ get_score_of_player(_int_ `player_index` ) + +--- +### `get_score_of_player()` +```tsx +pewpew.get_score_of_player(player_index: int): int +``` Returns the score of the player at the specified `player_index`. `player_index` must in the range [0, get_number_of_players() - 1]. -### _void_ configure_player(_int_ `player_index` , _Map_ \{_boolean_ has_lost , _int_ shield , _FixedPoint_ camera_x_override , _FixedPoint_ camera_y_override , _FixedPoint_ camera_distance , _FixedPoint_ camera_rotation_x_axis , _int_ move_joystick_color , _int_ shoot_joystick_color\} `configuration` ) + + +--- +### `configure_player()` +```tsx +pewpew.configure_player( + player_index: int, + configuration: table { + has_lost: bool, + shield: int, + camera_x_override: FixedPoint, + camera_y_override: FixedPoint, + camera_distance: FixedPoint, + camera_rotation_x_axis: FixedPoint, + move_joystick_color: int, + shoot_joystick_color: int + } +) +``` Configures the player at the specified `player_index`. `player_index` must in the range [0, get_number_of_players() - 1]. A `camera_distance` less than 0fx makes the camera move away from the ship. `camera_rotation_x_axis` is in radian and rotates along the X axis. - To temporarily override the XY position of the camera, set both `camera_x_override` and `camera_y_override`; this will make the camera be interpolated from wherever it was, to that new position. + To temporarily override the XY position of the camera, set **both** `camera_x_override` and `camera_y_override`; this will make the camera be interpolated from wherever it was, to that new position. + +> Example: > ```lua > pewpew.configure_player(0, {shield = 3, camera_distance = 50fx, move_joystick_color = 0xffff00ff}) > ``` -### _void_ configure_player_hud(_int_ `player_index` , _Map_ \{_String_ top_left_line\} `configuration` ) + +--- +### `configure_player_hud()` +```tsx +pewpew.configure_player_hud( + player_index: int, + configuration: table { + top_left_line: string + } +) +``` Configures the player's HUD.`player_index` must in the range [0, get_number_of_players() - 1]. + +> Example: > ```lua > pewpew.configure_player_hud(0, {top_left_line = "Hello World"}) > ``` -### _Map_ \{_int_ shield , _boolean_ has_lost\} get_player_configuration(_int_ `player_index` ) + +--- +### `get_player_configuration()` +```tsx +pewpew.get_player_configuration(player_index: int): table { + shield: int, + has_lost: bool + } +``` Returns a map containing the configuration of the player at the specified `player_index`. + +> Example: > ```lua > local shield = pewpew.get_player_configuration(0).shield > ``` -### _void_ configure_player_ship_weapon(_EntityId_ `ship_id` , _Map_ \{_int_ frequency , _int_ cannon , _int_ duration\} `configuration` ) + +--- +### `configure_player_ship_weapon()` +```tsx +pewpew.configure_player_ship_weapon( + ship_id: EntityId, + configuration: table { + frequency: int, + cannon: int, + duration: int + } +) +``` Configures the weapon of the ship identified with `ship_id` using `configuration`. `frequency` determines the frequency of the shots. `cannon` determines the type of cannon. `duration` determines the number of game ticks during which the weapon will be available. Once the duration expires, the weapon reverts to its permanent configuration. If `duration` is omitted, the weapon will be permanently set to this configuration. If `frequency` or `cannon` is omitted, the ship is configured to not have any weapon. + +> Example: > ```lua > local weapon_config = {frequency = pewpew.CannonFrequency.FREQ_10, cannon = pewpew.CannonType.DOUBLE} > local ship_id = player_helpers.new_player_ship(100fx, 200fx, 0) > pewpew.configure_player_ship_weapon(ship_id, weapon_config) > ``` -### _void_ add_damage_to_player_ship(_EntityId_ `ship_id` , _int_ `damage` ) + +--- +### `add_damage_to_player_ship()` +```tsx +pewpew.add_damage_to_player_ship( + ship_id: EntityId, + damage: int +) +``` Reduces the amount of shield of the player that owns the ship by `damage` points. If the player receives damage while having 0 shields left, the player loses. -### _int_ add_arrow_to_player_ship(_EntityId_ `ship_id` , _EntityId_ `target_id` , _int_ `color` ) + + +--- +### `add_arrow_to_player_ship()` +```tsx +pewpew.add_arrow_to_player_ship( + ship_id: EntityId, + target_id: EntityId, + color: int +): int +``` Adds an arrow to the ship identified with `ship_id` pointing towards the entity identified with `entity_id`, and returns the identifier of the arrow. `color` specifies the arrow's color. The arrow is automatically removed when the target entity is destroyed. -### _void_ remove_arrow_from_player_ship(_EntityId_ `ship_id` , _int_ `arrow_id` ) + + +--- +### `remove_arrow_from_player_ship()` +```tsx +pewpew.remove_arrow_from_player_ship( + ship_id: EntityId, + arrow_id: int +) +``` Removes the arrow identified by `arrow_id` from the ship identified by `ship_id`. -### _void_ make_player_ship_transparent(_EntityId_ `ship_id` , _int_ `transparency_duration` ) + + +--- +### `make_player_ship_transparent()` +```tsx +pewpew.make_player_ship_transparent( + ship_id: EntityId, + transparency_duration: int +) +``` Makes the player ship transparent for `transparency_duration` game ticks. -### _FixedPoint_ set_player_ship_speed(_EntityId_ `ship_id` , _FixedPoint_ `factor` , _FixedPoint_ `offset` , _int_ `duration` ) + + +--- +### `set_player_ship_speed()` +```tsx +pewpew.set_player_ship_speed( + ship_id: EntityId, + factor: FixedPoint, + offset: FixedPoint, + duration: int +): FixedPoint +``` Sets and returns the **effective speed** of the specified player ship as a function of the **base speed** of the ship. By default, a player ship moves according to its base speed, which is 10 distance units per tick (in the future, different ships may have different base speeds). Assuming the base speed of the ship is S, the new effective speed will be `(factor*S)+offset`. `duration` is the number of ticks during which the effective speed will be applied. Afterwards, the ship's speed reverts to its base speed. If `duration` is negative, the effective speed never reverts to the base speed. -### _List_ <_EntityId_> get_all_entities() + + +--- +### `get_all_entities()` +```tsx +pewpew.get_all_entities(): List +``` Returns the list of the entityIDs of all the entities currently in the level. This includes the various bullets and *all* the custom entities. + +> Example: > ```lua > local entities = pewpew.get_all_entities() > pewpew.print("There are " .. #entities .. " entities in the level") > ``` -### _List_ <_EntityId_> get_entities_colliding_with_disk(_FixedPoint_ `center_x` , _FixedPoint_ `center_y` , _FixedPoint_ `radius` ) + +--- +### `get_entities_colliding_with_disk()` +```tsx +pewpew.get_entities_colliding_with_disk( + center_x: FixedPoint, + center_y: FixedPoint, + radius: FixedPoint +): List +``` Returns the list of collidable entities (which includes all enemies) that overlap with the given disk. + +> Example: > ```lua > local entities = pewpew.get_entities_colliding_with_disk(100fx, 100fx, 30fx) > ``` -### _int_ get_entity_count(_int_ `type` ) + +--- +### `get_entity_count()` +```tsx +pewpew.get_entity_count(type: int): int +``` Returns the number of entities of type `type` that are alive. + +> Example: > ```lua > local number_of_bafs = pewpew.get_entity_count(pewpew.EntityType.BAF) > local number_of_asteroids = pewpew.get_entity_count(pewpew.EntityType.ASTEROID) > ``` -### _int_ get_entity_type(_EntityId_ `entity_id` ) + +--- +### `get_entity_type()` +```tsx +pewpew.get_entity_type(entity_id: EntityId): int +``` Returns the type of the given entity. + +> Example: > ```lua > local type = pewpew.get_entity_type(id) > if type == pewpew.EntityType.BAF then > pewpew.print("the entity is a BAF") > end > ``` -### _void_ play_ambient_sound(_String_ `sound_path` , _int_ `index` ) + +--- +### `play_ambient_sound()` +```tsx +pewpew.play_ambient_sound( + sound_path: string, + index: int +) +``` Plays the sound described at `sound_path` at the index `index`. + +> Example: > ```lua > pewpew.play_ambient_sound("/dynamic/my_custom_sound.lua", 0) > ``` -### _void_ play_sound(_String_ `sound_path` , _int_ `index` , _FixedPoint_ `x` , _FixedPoint_ `y` ) + +--- +### `play_sound()` +```tsx +pewpew.play_sound( + sound_path: string, + index: int, + x: FixedPoint, + y: FixedPoint +) +``` Plays the sound described at `sound_path` at the in-game location of `x`,`y`. + +> Example: > ```lua > pewpew.play_sound("/dynamic/my_custom_sound.lua", 0, 100fx, 100fx) > ``` -### _void_ create_explosion(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `color` , _FixedPoint_ `scale` , _int_ `particle_count` ) + +--- +### `create_explosion()` +```tsx +pewpew.create_explosion( + x: FixedPoint, + y: FixedPoint, + color: int, + scale: FixedPoint, + particle_count: int +) +``` Creates an explosion of particles at the location `x`,`y`. `color` specifies the color of the explosion. `scale` describes how large the explosion will be. It should be in the range ]0, 10], with 1 being an average explosion. `particle_count` specifies the number of particles that make up the explosion. It must be in the range [1, 100]. + +> Example: > ```lua > pewpew.create_explosion(200fx, 100fx, 0xffffffff, 1fx, 20) -- medium explosion > pewpew.create_explosion(300fx, 100fx, 0xffffffff, 3fx, 50) -- large red explosion > ``` -### _EntityId_ new_asteroid(_FixedPoint_ `x` , _FixedPoint_ `y` ) + +--- +### `new_asteroid()` +```tsx +pewpew.new_asteroid( + x: FixedPoint, + y: FixedPoint +): EntityId +``` Creates a new Asteroid at the location `x`,`y` and returns its entityId. -### _EntityId_ new_asteroid_with_size(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `size` ) + + +--- +### `new_asteroid_with_size()` +```tsx +pewpew.new_asteroid_with_size( + x: FixedPoint, + y: FixedPoint, + size: int +): EntityId +``` Creates a new Asteroid at the location `x`,`y` with an AsteroidSize given by `size` and returns its entityId. -### _EntityId_ new_baf(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `angle` , _FixedPoint_ `speed` , _int_ `lifetime` ) + + +--- +### `new_baf()` +```tsx +pewpew.new_baf( + x: FixedPoint, + y: FixedPoint, + angle: FixedPoint, + speed: FixedPoint, + lifetime: int +): EntityId +``` Creates a new BAF at the location `x`,`y`, and returns its entityId. `angle` specifies the angle at which the BAF will move. `speed` specifies the maximum speed it will reach. `lifetime` indicates the number of game ticks after which the BAF is destroyed the next time it hits a wall. Specify a negative `lifetime` to create a BAF that lives forever. -### _EntityId_ new_baf_red(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `angle` , _FixedPoint_ `speed` , _int_ `lifetime` ) + + +--- +### `new_baf_red()` +```tsx +pewpew.new_baf_red( + x: FixedPoint, + y: FixedPoint, + angle: FixedPoint, + speed: FixedPoint, + lifetime: int +): EntityId +``` Creates a new red BAF at the location `x`,`y`, and returns its entityId. A red BAF has more health points than a regular BAF. `angle` specifies the angle at which the BAF will move. `speed` specifies the maximum speed it will reach. `lifetime` indicates the number of game ticks after which the BAF is destroyed the next time it hits a wall. Specify a negative `lifetime` to create a BAF that lives forever. -### _EntityId_ new_baf_blue(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `angle` , _FixedPoint_ `speed` , _int_ `lifetime` ) + + +--- +### `new_baf_blue()` +```tsx +pewpew.new_baf_blue( + x: FixedPoint, + y: FixedPoint, + angle: FixedPoint, + speed: FixedPoint, + lifetime: int +): EntityId +``` Creates a new blue BAF at the location `x`,`y`, and returns its entityId. A blue BAF bounces on walls with a slightly randomized angle. `angle` specifies the angle at which the BAF will move. `speed` specifies the maximum speed it will reach. `lifetime` indicates the number of game ticks after which the BAF is destroyed the next time it hits a wall. Specify a negative `lifetime` to create a BAF that lives forever. -### _EntityId_ new_bomb(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `type` ) + + +--- +### `new_bomb()` +```tsx +pewpew.new_bomb( + x: FixedPoint, + y: FixedPoint, + type: int +): EntityId +``` Creates a new Bomb at the location `x`,`y`, and returns its entityId. + +> Example: > ```lua > pewpew.new_bomb(10fx, 10fx, pewpew.BombType.SMALL_ATOMIZE) > ``` -### _EntityId_ new_bonus(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `type` , _Map_ \{_int_ box_duration , _int_ cannon , _int_ frequency , _int_ weapon_duration , _int_ number_of_shields , _FixedPoint_ speed_factor , _FixedPoint_ speed_offset , _int_ speed_duration , _Callback_ taken_callback\} `config` ) + +--- +### `new_bonus()` +```tsx +pewpew.new_bonus( + x: FixedPoint, + y: FixedPoint, + type: int, + config: table { + box_duration: int, + cannon: int, + frequency: int, + weapon_duration: int, + number_of_shields: int, + speed_factor: FixedPoint, + speed_offset: FixedPoint, + speed_duration: int, + taken_callback: function + } +): EntityId +``` Creates a new Bonus at the location `x`,`y` of the type `type`, and returns its entityId. For shield bonuses, the option `number_of_shields` determines how many shields are given out. For weapon bonuses, the options `cannon`, `frequency`, `weapon_duration` have the same meaning as in `pewpew.configure_player_ship_weapon`. For speed bonuses, the options `speed_factor`, `speed_offset`,and `speed_duration` have the same meaning as in `set_player_speed`. `taken_callback` is called when the bonus is taken, and is mandatory for the reinstantiation bonus. The callback receives as arguments the entity id of the bonus, the player id, and the ship's entity id. The default box duration is 400 ticks. + +> Example: > ```lua > pewpew.new_bonus(10fx, 10fx, pewpew.BonusType.WEAPON, {cannon = pewpew.CannonType.TIC_TOC, frequency = pewpew.CannonFrequency.FREQ_5, weapon_duration = 100}) > pewpew.new_bonus(10fx, 10fx, pewpew.BonusType.SHIELD, {number_of_shields = 3}) > ``` -### _EntityId_ new_crowder(_FixedPoint_ `x` , _FixedPoint_ `y` ) + +--- +### `new_crowder()` +```tsx +pewpew.new_crowder( + x: FixedPoint, + y: FixedPoint +): EntityId +``` Creates a new Crowder at the location `x`,`y`, and returns its entityId. -### _EntityId_ new_floating_message(_FixedPoint_ `x` , _FixedPoint_ `y` , _String_ `str` , _Map_ \{_FixedPoint_ scale , _int_ ticks_before_fade , _boolean_ is_optional\} `config` ) + + +--- +### `new_floating_message()` +```tsx +pewpew.new_floating_message( + x: FixedPoint, + y: FixedPoint, + str: string, + config: table { + scale: FixedPoint, + ticks_before_fade: int, + is_optional: bool + } +): EntityId +``` Creates a new floating message at the location `x`,`y`, with `str` as the message. The scale is a number that determines how large the message will be. `1` is the default scale. `ticks_before_fade` determines how many ticks occur before the message starts to fade out. `is_optional` can be used to tell the game if the message can be hidden depending on the user's UI settings. If not specified, `scale` is 1, `ticks_before_fade` is 30 and `is_optional` is `false`. Returns the floating message's entityId. + +> Example: > ```lua > pewpew.new_floating_message(10fx, 10fx, "hello", {scale = 2fx, ticks_before_fade = 60, is_optional = true}) > ``` -### _EntityId_ new_customizable_entity(_FixedPoint_ `x` , _FixedPoint_ `y` ) + +--- +### `new_customizable_entity()` +```tsx +pewpew.new_customizable_entity( + x: FixedPoint, + y: FixedPoint +): EntityId +``` Creates a new customizable entity at the location `x`,`y`, and returns its entityId. -### _EntityId_ new_inertiac(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `acceleration` , _FixedPoint_ `angle` ) + + +--- +### `new_inertiac()` +```tsx +pewpew.new_inertiac( + x: FixedPoint, + y: FixedPoint, + acceleration: FixedPoint, + angle: FixedPoint +): EntityId +``` Creates a new Inertiac at the location `x`,`y`, and returns its entityId. The inertiac will accelerate according to `acceleration`. It spawns with a random velocity in a direction specified by `angle`. -### _EntityId_ new_mothership(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `type` , _FixedPoint_ `angle` ) + + +--- +### `new_mothership()` +```tsx +pewpew.new_mothership( + x: FixedPoint, + y: FixedPoint, + type: int, + angle: FixedPoint +): EntityId +``` Creates a new Mothership at the location `x`,`y`, and returns its entityId. + +> Example: > ```lua > pewpew.new_mothership(50fx, 50fx, pewpew.MothershipType.THREE_CORNERS, fmath.tau() / 4fx) > ``` -### _EntityId_ new_pointonium(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `value` ) + +--- +### `new_pointonium()` +```tsx +pewpew.new_pointonium( + x: FixedPoint, + y: FixedPoint, + value: int +): EntityId +``` Creates a new Pointonium at the location `x`,`y`. Value must be 64, 128, or 256. -### _EntityId_ new_player_ship(_FixedPoint_ `x` , _FixedPoint_ `y` , _int_ `player_index` ) + + +--- +### `new_player_ship()` +```tsx +pewpew.new_player_ship( + x: FixedPoint, + y: FixedPoint, + player_index: int +): EntityId +``` Creates a new Player Ship at the location `x`,`y` for the player identified by `player_index`, and returns its entityId. -### _EntityId_ new_player_bullet(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `angle` , _int_ `player_index` ) + + +--- +### `new_player_bullet()` +```tsx +pewpew.new_player_bullet( + x: FixedPoint, + y: FixedPoint, + angle: FixedPoint, + player_index: int +): EntityId +``` Creates a new bullet at the location `x`,`y` with the angle `angle` belonging to the player at the index `player_index`. Returns the entityId of the bullet. -### _EntityId_ new_rolling_cube(_FixedPoint_ `x` , _FixedPoint_ `y` ) + + +--- +### `new_rolling_cube()` +```tsx +pewpew.new_rolling_cube( + x: FixedPoint, + y: FixedPoint +): EntityId +``` Creates a new Rolling Cube at the location `x`,`y`, and returns its entityId. -### _EntityId_ new_rolling_sphere(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `angle` , _FixedPoint_ `speed` ) + + +--- +### `new_rolling_sphere()` +```tsx +pewpew.new_rolling_sphere( + x: FixedPoint, + y: FixedPoint, + angle: FixedPoint, + speed: FixedPoint +): EntityId +``` Creates a new Rolling Sphere at the location `x`,`y`, and returns its entityId. -### _EntityId_ new_wary(_FixedPoint_ `x` , _FixedPoint_ `y` ) + + +--- +### `new_wary()` +```tsx +pewpew.new_wary( + x: FixedPoint, + y: FixedPoint +): EntityId +``` Creates a new Wary at the location `x`,`y`. -### _EntityId_ new_ufo(_FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `dx` ) + + +--- +### `new_ufo()` +```tsx +pewpew.new_ufo( + x: FixedPoint, + y: FixedPoint, + dx: FixedPoint +): EntityId +``` Creates a new UFO at the location `x`,`y` moving horizontally at the speed of `dx`, and returns its entityId. -### _void_ rolling_cube_set_enable_collisions_with_walls(_EntityId_ `entity_id` , _boolean_ `collide_with_walls` ) + + +--- +### `rolling_cube_set_enable_collisions_with_walls()` +```tsx +pewpew.rolling_cube_set_enable_collisions_with_walls( + entity_id: EntityId, + collide_with_walls: bool +) +``` Sets whether the rolling cube identified with `id` collides with walls. By default it does not. + +> Example: > ```lua > local x,y = pewpew.rolling_cube_set_enable_collisions_with_walls(id, true) > ``` -### _void_ ufo_set_enable_collisions_with_walls(_EntityId_ `entity_id` , _boolean_ `collide_with_walls` ) + +--- +### `ufo_set_enable_collisions_with_walls()` +```tsx +pewpew.ufo_set_enable_collisions_with_walls( + entity_id: EntityId, + collide_with_walls: bool +) +``` Sets whether the ufo identified with `id` collides with walls. By default it does not. + +> Example: > ```lua > local x,y = pewpew.ufo_set_enable_collisions_with_walls(id, true) > ``` -### _FixedPoint_, _FixedPoint_ entity_get_position(_EntityId_ `entity_id` ) + +--- +### `entity_get_position()` +```tsx +pewpew.entity_get_position(entity_id: EntityId): FixedPoint, FixedPoint +``` Returns the position of the entity identified by `id`. + +> Example: > ```lua > local x,y = pewpew.entity_get_position(entity_id) > ``` -### _boolean_ entity_get_is_alive(_EntityId_ `entity_id` ) + +--- +### `entity_get_is_alive()` +```tsx +pewpew.entity_get_is_alive(entity_id: EntityId): bool +``` Returns whether the entity identified by `id` is alive or not. -### _boolean_ entity_get_is_started_to_be_destroyed(_EntityId_ `entity_id` ) + + +--- +### `entity_get_is_started_to_be_destroyed()` +```tsx +pewpew.entity_get_is_started_to_be_destroyed(entity_id: EntityId): bool +``` Returns whether the entity identified by `id` is in the process of being destroyed. Returns false if the entity does not exist. -### _void_ entity_set_position(_EntityId_ `entity_id` , _FixedPoint_ `x` , _FixedPoint_ `y` ) + + +--- +### `entity_set_position()` +```tsx +pewpew.entity_set_position( + entity_id: EntityId, + x: FixedPoint, + y: FixedPoint +) +``` Sets the position of the entity identified by `id` to `x`,`y` -### _void_ entity_set_radius(_EntityId_ `entity_id` , _FixedPoint_ `radius` ) + + +--- +### `entity_set_radius()` +```tsx +pewpew.entity_set_radius( + entity_id: EntityId, + radius: FixedPoint +) +``` Sets the radius of the entity identified by `id`. To give you a sense of scale, motherships have a radius of 28fx. -### _void_ entity_set_update_callback(_EntityId_ `entity_id` , _Callback_ `callback` ) + + +--- +### `entity_set_update_callback()` +```tsx +pewpew.entity_set_update_callback( + entity_id: EntityId, + callback: function +) +``` Sets a callback that will be called at every tick as long as the entity identified by `id` is alive. Remove the callback by passing a nil `callback`. The callbacks gets called with the entity ID. + +> Example: > ```lua > local function my_update_callback(entity_id) > local x,y = pewpew.entity_get_position(entity_id) @@ -377,60 +853,241 @@ Sets a callback that will be called at every tick as long as the entity identifi > end > pewpew.entity_set_update_callback(entity_id, my_update_callback) > ``` -### _void_ entity_destroy(_EntityId_ `entity_id` ) + +--- +### `entity_destroy()` +```tsx +pewpew.entity_destroy(entity_id: EntityId) +``` Makes the entity identified by `id` immediately disappear forever. -### _boolean_ entity_react_to_weapon(_EntityId_ `entity_id` , _Map_ \{_int_ type , _FixedPoint_ x , _FixedPoint_ y , _int_ player_index\} `weapon` ) + + +--- +### `entity_react_to_weapon()` +```tsx +pewpew.entity_react_to_weapon( + entity_id: EntityId, + weapon: table { + type: int, + x: FixedPoint, + y: FixedPoint, + player_index: int + } +): bool +``` Makes the entity identified by `id` react to the weapon described in `weapon_description`. Returns whether the entity reacted to the weapon. The returned value is typically used to decide whether the weapon should continue to exist or not. In the case of an explosion, `x` and `y` should store the origin of the explosion. In the case of a bullet, `x` and `y` should store the vector of the bullet. The player identified by `player_index` will be assigned points. If `player_index` is invalid, no player will be assigned points. -### _void_ customizable_entity_set_position_interpolation(_EntityId_ `entity_id` , _boolean_ `enable` ) + + +--- +### `customizable_entity_set_position_interpolation()` +```tsx +pewpew.customizable_entity_set_position_interpolation( + entity_id: EntityId, + enable: bool +) +``` Sets whether the position of the mesh wil be interpolated when rendering. In general, this should be set to true if the entity will be moving smoothly. -### _void_ customizable_entity_set_mesh(_EntityId_ `entity_id` , _String_ `file_path` , _int_ `index` ) + + +--- +### `customizable_entity_set_mesh()` +```tsx +pewpew.customizable_entity_set_mesh( + entity_id: EntityId, + file_path: string, + index: int +) +``` Sets the mesh of the customizable entity identified by `id` to the mesh described in the file `file_path` at the index `index`. `index` starts at 0. If `file_path` is an empty string, the mesh is removed. + +> Example: > ```lua > local id = pewpew.new_customizable_entity(0fx, 0fx) > pewpew.customizable_entity_set_mesh(id, "/dynamic/graphics.lua", 0) > ``` -### _void_ customizable_entity_set_flipping_meshes(_EntityId_ `entity_id` , _String_ `file_path` , _int_ `index_0` , _int_ `index_1` ) + +--- +### `customizable_entity_set_flipping_meshes()` +```tsx +pewpew.customizable_entity_set_flipping_meshes( + entity_id: EntityId, + file_path: string, + index_0: int, + index_1: int +) +``` Similar to `customizable_entity_set_mesh`, but sets two meshes that will be used in alternation. By specifying 2 separate meshes, 60 fps animations can be achieved. + +> Example: > ```lua > local id = pewpew.new_customizable_entity(0fx, 0fx) > pewpew.customizable_entity_set_flipping_meshes(id, "/dynamic/graphics.lua", 0, 1) > ``` -### _void_ customizable_entity_set_mesh_color(_EntityId_ `entity_id` , _int_ `color` ) + +--- +### `customizable_entity_set_mesh_color()` +```tsx +pewpew.customizable_entity_set_mesh_color( + entity_id: EntityId, + color: int +) +``` Sets the color multiplier for the mesh of the customizable entity identified by `id`. -### _void_ customizable_entity_set_string(_EntityId_ `entity_id` , _String_ `text` ) + + +--- +### `customizable_entity_set_string()` +```tsx +pewpew.customizable_entity_set_string( + entity_id: EntityId, + text: string +) +``` Sets the string to be displayed as part of the mesh of the customizable entity identified by `id`. -### _void_ customizable_entity_set_mesh_xyz(_EntityId_ `entity_id` , _FixedPoint_ `x` , _FixedPoint_ `y` , _FixedPoint_ `z` ) + + +--- +### `customizable_entity_set_mesh_xyz()` +```tsx +pewpew.customizable_entity_set_mesh_xyz( + entity_id: EntityId, + x: FixedPoint, + y: FixedPoint, + z: FixedPoint +) +``` Sets the position of the mesh to x,y,z, relative to the center ofthe customizable entity identified by `id` -### _void_ customizable_entity_set_mesh_z(_EntityId_ `entity_id` , _FixedPoint_ `z` ) + + +--- +### `customizable_entity_set_mesh_z()` +```tsx +pewpew.customizable_entity_set_mesh_z( + entity_id: EntityId, + z: FixedPoint +) +``` Sets the height of the mesh of the customizable entity identified by `id`. A `z` greater to 0 makes the mesh be closer, while a `z` less than 0 makes the mesh be further away. -### _void_ customizable_entity_set_mesh_scale(_EntityId_ `entity_id` , _FixedPoint_ `scale` ) + + +--- +### `customizable_entity_set_mesh_scale()` +```tsx +pewpew.customizable_entity_set_mesh_scale( + entity_id: EntityId, + scale: FixedPoint +) +``` Sets the scale of the mesh of the customizable entity identified by `id`. A `scale` less than 1 makes the mesh appear smaller, while a `scale` greater than 1 makes the mesh appear larger. -### _void_ customizable_entity_set_mesh_xyz_scale(_EntityId_ `entity_id` , _FixedPoint_ `x_scale` , _FixedPoint_ `y_scale` , _FixedPoint_ `z_scale` ) + + +--- +### `customizable_entity_set_mesh_xyz_scale()` +```tsx +pewpew.customizable_entity_set_mesh_xyz_scale( + entity_id: EntityId, + x_scale: FixedPoint, + y_scale: FixedPoint, + z_scale: FixedPoint +) +``` Sets the scale of the mesh of the customizable entity identified by `id` along the x,y,z axis. A `scale` less than 1 makes the mesh appear smaller, while a `scale` greater than 1 makes the mesh appear larger. -### _void_ customizable_entity_set_mesh_angle(_EntityId_ `entity_id` , _FixedPoint_ `angle` , _FixedPoint_ `x_axis` , _FixedPoint_ `y_axis` , _FixedPoint_ `z_axis` ) + + +--- +### `customizable_entity_set_mesh_angle()` +```tsx +pewpew.customizable_entity_set_mesh_angle( + entity_id: EntityId, + angle: FixedPoint, + x_axis: FixedPoint, + y_axis: FixedPoint, + z_axis: FixedPoint +) +``` Sets the rotation angle of the mesh of the customizable entity identified by `id`. The rotation is applied along the axis defined by `x_axis`,`y_axis`,`z_axis`. + +> Example: > ```lua > -- Rotate the entity by 45 degrees along the z_axis > pewpew.customizable_entity_set_mesh_angle(entity_id, fmath.tau() / 8fx, 0fx, 0fx, 1fx) > ``` -### _void_ customizable_entity_skip_mesh_attributes_interpolation(_EntityId_ `entity_id` ) + +--- +### `customizable_entity_skip_mesh_attributes_interpolation()` +```tsx +pewpew.customizable_entity_skip_mesh_attributes_interpolation(entity_id: EntityId) +``` Skips the interpolation of the mesh's attributes (x, y, z, scale_x, scale_y, scale_z, rotation). -### _void_ customizable_entity_configure_music_response(_EntityId_ `entity_id` , _Map_ \{_int_ color_start , _int_ color_end , _FixedPoint_ scale_x_start , _FixedPoint_ scale_x_end , _FixedPoint_ scale_y_start , _FixedPoint_ scale_y_end , _FixedPoint_ scale_z_start , _FixedPoint_ scale_z_end\} `config` ) + + +--- +### `customizable_entity_configure_music_response()` +```tsx +pewpew.customizable_entity_configure_music_response( + entity_id: EntityId, + config: table { + color_start: int, + color_end: int, + scale_x_start: FixedPoint, + scale_x_end: FixedPoint, + scale_y_start: FixedPoint, + scale_y_end: FixedPoint, + scale_z_start: FixedPoint, + scale_z_end: FixedPoint + } +) +``` Configures the way the entity is going to respond to the music. + +> Example: > ```lua > -- Makes the entity larger > pewpew.customizable_entity_configure_music_response(entity_id, {scale_x_start = 1fx, scale_x_end = 2fx}) > ``` -### _void_ customizable_entity_add_rotation_to_mesh(_EntityId_ `entity_id` , _FixedPoint_ `angle` , _FixedPoint_ `x_axis` , _FixedPoint_ `y_axis` , _FixedPoint_ `z_axis` ) + +--- +### `customizable_entity_add_rotation_to_mesh()` +```tsx +pewpew.customizable_entity_add_rotation_to_mesh( + entity_id: EntityId, + angle: FixedPoint, + x_axis: FixedPoint, + y_axis: FixedPoint, + z_axis: FixedPoint +) +``` Adds a rotation to the mesh of the customizable entity identified by `id`. The rotation is applied along the axis defined by `x_axis`,`y_axis`,`z_axis`. + +> Example: > ```lua > -- Rotate the entity by 45 degrees along the z_axis > pewpew.customizable_entity_add_rotation_to_mesh(entity_id, fmath.tau() / 8fx, 0fx, 0fx, 1fx) > ``` -### _void_ customizable_entity_set_visibility_radius(_EntityId_ `entity_id` , _FixedPoint_ `radius` ) + +--- +### `customizable_entity_set_visibility_radius()` +```tsx +pewpew.customizable_entity_set_visibility_radius( + entity_id: EntityId, + radius: FixedPoint +) +``` Sets the radius defining the visibility of the entity. This allows the game to know when an entity is actually visible, which in turns allows to massively optimize the rendering. Use the smallest value possible. If not set, the rendering radius is an unspecified large number that effectively makes the entity always be rendered, even if not visible. -### _void_ customizable_entity_configure_wall_collision(_EntityId_ `entity_id` , _boolean_ `collide_with_walls` , _Callback_ `collision_callback` ) + + +--- +### `customizable_entity_configure_wall_collision()` +```tsx +pewpew.customizable_entity_configure_wall_collision( + entity_id: EntityId, + collide_with_walls: bool, + collision_callback: function +) +``` `collide_with_walls` configures whether the entity should stop when colliding with walls. If `collision_callback` is not nil, it is called anytime a collision is detected. The callback gets called with the entity id of the entity withthe callback, and with the normal to the wall. + +> Example: > ```lua > function my_wall_collision_callback(entity_id, wall_normal_x, wall_normal_y) > pewpew.print("A wall collision happened with entity " .. entity_id) @@ -438,8 +1095,18 @@ Sets the radius defining the visibility of the entity. This allows the game to k > local id = pewpew.new_customizable_entity(100fx, 100fx) > pewpew.customizable_entity_configure_wall_collision(id, my_wall_collision_callback) > ``` -### _void_ customizable_entity_set_player_collision_callback(_EntityId_ `entity_id` , _Callback_ `collision_callback` ) + +--- +### `customizable_entity_set_player_collision_callback()` +```tsx +pewpew.customizable_entity_set_player_collision_callback( + entity_id: EntityId, + collision_callback: function +) +``` Sets the callback for when the customizable entity identified by `id` collides with a player's ship. The callback gets called with the entity id of the entity with the callback, and the player_index and ship_id that were involved in the collision. Don't forget to set a radius on the customizable entity, otherwise no collisions will be detected. + +> Example: > ```lua > function my_collision_callback(entity_id, player_index, ship_entity_id) > pewpew.print("The entity: " .. entity_id) @@ -449,8 +1116,18 @@ Sets the callback for when the customizable entity identified by `id` collides w > local id = pewpew.new_customizable_entity(100fx, 100fx) > pewpew.customizable_entity_set_player_collision_callback(id, my_collision_callback) > ``` -### _void_ customizable_entity_set_weapon_collision_callback(_EntityId_ `entity_id` , _Callback_ `weapon_collision_callback` ) + +--- +### `customizable_entity_set_weapon_collision_callback()` +```tsx +pewpew.customizable_entity_set_weapon_collision_callback( + entity_id: EntityId, + weapon_collision_callback: function +) +``` Sets the callback for when the customizable entity identified by `id` collides with a player's weapon. The callback gets called with the entity_id of the entity on which the callback is set, the player_index of the player that triggered the weapon, and the type of the weapon. The callback *must* return a boolean saying whether the entity reacts to the weapon. In the case of a bullet, this boolean determines whether the bullet should be destroyed. + +> Example: > ```lua > local id = pewpew.new_customizable_entity(100fx, 100fx) > pewpew.customizable_entity_set_weapon_collision_callback(id, function(entity_id, player_index, weapon_type) @@ -461,7 +1138,25 @@ Sets the callback for when the customizable entity identified by `id` collides w > return true > end) > ``` -### _void_ customizable_entity_start_spawning(_EntityId_ `entity_id` , _int_ `spawning_duration` ) + +--- +### `customizable_entity_start_spawning()` +```tsx +pewpew.customizable_entity_start_spawning( + entity_id: EntityId, + spawning_duration: int +) +``` Makes the customizable entity identified by `id` spawn for a duration of `spawning_duration` game ticks. -### _void_ customizable_entity_start_exploding(_EntityId_ `entity_id` , _int_ `explosion_duration` ) + + +--- +### `customizable_entity_start_exploding()` +```tsx +pewpew.customizable_entity_start_exploding( + entity_id: EntityId, + explosion_duration: int +) +``` Makes the customizable entity identified by `id` explode for a duration of `explosion_duration` game ticks. After the explosion, the entity is destroyed. `explosion_duration` must be less than 255. Any scale applied to the entity is also applied to the explosion. + diff --git a/docs/api/_category_.json b/docs/api/_category_.json deleted file mode 100644 index 98c08b1..0000000 --- a/docs/api/_category_.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "label": "API", - "position": 6, - "link": { - "type": "generated-index", - "description": "API documentation for libraries used in PewPew Live." - } -} diff --git a/docs/api/fmath-library.md b/docs/api/fmath-library.md deleted file mode 100644 index 49a6a82..0000000 --- a/docs/api/fmath-library.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -sidebar_position: 3 ---- - -# fmath library - -[//]: # "This file is automatically generated." -[//]: # "Manual edits will be overwritten." - -`fmath` contains a set of mathematical functions that work with FixedPoint numbers and integers. `fmath` replaces lua's `math` library in game scripts (you can use Lua's `math` library outside of game scripts). -* [max_fixedpoint()](#fixedpoint-max_fixedpoint) -* [random_fixedpoint(min, max)](#fixedpoint-random_fixedpointfixedpoint-min--fixedpoint-max-) -* [random_int(min, max)](#int-random_intint-min--int-max-) -* [sqrt(x)](#fixedpoint-sqrtfixedpoint-x-) -* [from_fraction(numerator, denominator)](#fixedpoint-from_fractionint-numerator--int-denominator-) -* [to_int(value)](#int-to_intfixedpoint-value-) -* [abs_fixedpoint(value)](#fixedpoint-abs_fixedpointfixedpoint-value-) -* [to_fixedpoint(value)](#fixedpoint-to_fixedpointint-value-) -* [sincos(angle)](#fixedpoint-fixedpoint-sincosfixedpoint-angle-) -* [atan2(y, x)](#fixedpoint-atan2fixedpoint-y--fixedpoint-x-) -* [tau()](#fixedpoint-tau) -## functions -### _FixedPoint_ max_fixedpoint() -Returns the maximum value a fixedpoint integer can take. -### _FixedPoint_ random_fixedpoint(_FixedPoint_ `min` , _FixedPoint_ `max` ) -Returns a random fixedpoint value in the range [`min`, `max`]. `max` must be greater or equal to `min`. -### _int_ random_int(_int_ `min` , _int_ `max` ) -Returns an integer in the range [`min`, `max`]. `max` must be greater or equal to `min`. -### _FixedPoint_ sqrt(_FixedPoint_ `x` ) -Returns the square root of `x`. `x` must be greater or equal to 0. -### _FixedPoint_ from_fraction(_int_ `numerator` , _int_ `denominator` ) -Returns the fixedpoint value representing the fraction `numerator`/`denominator`. `denominator` must not be equal to zero. -### _int_ to_int(_FixedPoint_ `value` ) -Returns the integral part of the `value`. -### _FixedPoint_ abs_fixedpoint(_FixedPoint_ `value` ) -Returns the absolute value. -### _FixedPoint_ to_fixedpoint(_int_ `value` ) -Returns a fixedpoint value with the integral part of `value`, and no fractional part. -### _FixedPoint_, _FixedPoint_ sincos(_FixedPoint_ `angle` ) -Returns the sinus and cosinus of `angle`. `angle` is in radian. -### _FixedPoint_ atan2(_FixedPoint_ `y` , _FixedPoint_ `x` ) -Returns the principal value of the arc tangent of y/x. Returns a value in the range [0, 2π[. -### _FixedPoint_ tau() -Returns τ (aka 2π). diff --git a/docs/api/types.mdx b/docs/api/types.mdx index 78a18f8..255c877 100644 --- a/docs/api/types.mdx +++ b/docs/api/types.mdx @@ -58,5 +58,4 @@ Typically used to hold text and file paths. The API only accepts strings less th ## float -Stores floating point numbers. Because they make determinism hard to guarantee, floats must only be used in Lua scripts that define meshes or sounds. Although it is still technically possible to use floats in game scripts, they will eventually be forbidden. -../../src/components/fx-converter \ No newline at end of file +Stores floating point numbers. Because they make determinism hard to guarantee, floats must only be used in Lua scripts that define meshes or sounds. Although it is still technically possible to use floats in game scripts, they will eventually be forbidden. \ No newline at end of file diff --git a/docs/file-information/_category_.json b/docs/file-information/_category_.json deleted file mode 100644 index 0c99bdf..0000000 --- a/docs/file-information/_category_.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "label": "File information", - "position": 5, - "link": { - "type": "generated-index", - "description": "Master your Lua programming skills with these guides" - } -} diff --git a/docs/intro.md b/docs/intro.md index 0351742..7fc8620 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -6,30 +6,30 @@ sidebar_position: 1 This community-maintained wiki holds the resources useful for creating custom levels for PewPew Live. -Levels are created by writing Lua code. If you are new to programming or new to Lua, a good first step is to start with the [Beginner](lua-guides/beginner) guide. +Levels are created by writing Lua code. If you are new to programming or new to Lua, a good first step is to start with the [Beginner](Guides/Lua/beginner) guide. If you are already familiar with programming, a good approach is to first look at the examples (for example, the [simple_level]) to get a feeling of how a level is made, and then come back to the wiki to get more precise information about the various aspect of level creation. If you have questions, the game's creator and many level creators are available on [Discord]. -# Level structure +## Level structure -A level is a directory that contains a [manifest](file-information/manifest-files) and Lua files. The Lua files fall in three categories: +A level is a directory that contains a [manifest](File%20Information/manifest-files) and Lua files. The Lua files fall in three categories: -- Files that describe [graphics](file-information/mesh-files). -- Files that describe [sounds](file-information/sound-files). -- Files that describe the behavior of the level. They make use of the [pewpew](api/pewpew-library) and [fmath](api/fmath-library) libraries, which require an understanding of the [types](api/types) used. +- Files that describe [graphics](File%20Information/mesh-files). +- Files that describe [sounds](File%20Information/sound-files). +- Files that describe the behavior of the level. They make use of the [pewpew](API/PewPew) and [fmath](API/Fmath) libraries, which require an understanding of the [types](API/types) used. -# Uploading your level +## Uploading your level You can upload your level by signing into your account on [https://pewpew.live] and navigating to the _Manage your custom levels_ page. -# Recommended Lua Style guide +## Recommended Lua Style guide When writing code, it is recommended to follow [LuaRocks's style guide], but using 2 space indentation to be consistent with the rest of PewPew's codebase. -# Helpful tools and utilities +## Helpful tools and utilities - [PewPew Snippets] is an essential Visual Studio Code extension that offers autocompletion and useful code snippets for creating levels. - [PewPewLive-MeshExporter] is a Blender plugin for converting scenes into PewPew Live 3D meshes. diff --git a/docs/lua-guides/_category_.json b/docs/lua-guides/_category_.json deleted file mode 100644 index cd521b0..0000000 --- a/docs/lua-guides/_category_.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "label": "Lua programming guides", - "position": 4, - "link": { - "type": "generated-index", - "description": "Information on various filetypes used in PewPew Live" - } -} diff --git a/docs/other-guides/_category_.json b/docs/other-guides/_category_.json deleted file mode 100644 index acacf67..0000000 --- a/docs/other-guides/_category_.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "label": "Other guides", - "position": 3, - "link": { - "type": "generated-index", - "description": "Guides for level development by the community!" - } -} diff --git a/docs/other/_category_.json b/docs/other/_category_.json deleted file mode 100644 index ec913c7..0000000 --- a/docs/other/_category_.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "label": "Miscellaneous", - "position": 7, - "link": { - "type": "generated-index", - "description": "Miscellaneous information for PewPew Live" - } -} diff --git a/docusaurus.config.ts b/docusaurus.config.ts index c133685..bcaa378 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -1,42 +1,27 @@ -import { themes as prismThemes } from "prism-react-renderer" -import type { Config } from "@docusaurus/types" -import type * as Preset from "@docusaurus/preset-classic" +import { themes as prismThemes } from "prism-react-renderer"; +import type { Config } from "@docusaurus/types"; +import type * as Preset from "@docusaurus/preset-classic"; const config: Config = { title: "PPL Docs", tagline: "Documentation for PewPew Live", favicon: "img/favicon.ico", - - // Set the production url of your site here url: "https://pewpewlive.github.io/", - // Set the // pathname under which your site is served - // For GitHub pages deployment, it is often '//' baseUrl: "/ppl-docs/", - - // GitHub pages deployment config. - // If you aren't using GitHub pages, you don't need these. - organizationName: "pewpewlive", // Usually your GitHub org/user name. - projectName: "docs", // Usually your repo name. - + organizationName: "pewpewlive", + projectName: "docs", onBrokenLinks: "throw", onBrokenMarkdownLinks: "warn", - - // Even if you don't use internationalization, you can use this field to set - // useful metadata like html lang. For example, if your site is Chinese, you - // may want to replace "en" with "zh-Hans". i18n: { defaultLocale: "en", locales: ["en"], }, - presets: [ [ "classic", { docs: { sidebarPath: "./sidebars.ts", - // Please change this to your repo. - // Remove this to remove the "edit this page" links. editUrl: "https://github.com/pewpewlive/ppl-docs/edit/master/", }, blog: { @@ -48,10 +33,7 @@ const config: Config = { } satisfies Preset.Options, ], ], - themeConfig: { - // Replace with your project's social card - // image: "img/docusaurus-social-card.jpg", navbar: { title: "PPL Docs", logo: { @@ -114,15 +96,18 @@ const config: Config = { ], copyright: `Copyright © ${new Date().getFullYear()} pewpewlive. Licensed under MIT. Built with Docusaurus.`, }, + docs: { + sidebar: { + autoCollapseCategories: false, + }, + }, prism: { - theme: prismThemes.github, - darkTheme: prismThemes.dracula, + theme: prismThemes.oneDark, + darkTheme: prismThemes.oneDark, additionalLanguages: ["json", "lua"], }, } satisfies Preset.ThemeConfig, - themes: [ - require.resolve("@easyops-cn/docusaurus-search-local"), - ], -} + themes: [require.resolve("@easyops-cn/docusaurus-search-local")], +}; -export default config +export default config; diff --git a/sidebars.ts b/sidebars.ts index acc7685..7c9717a 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -1,31 +1,7 @@ -import type {SidebarsConfig} from '@docusaurus/plugin-content-docs'; +import type { SidebarsConfig } from "@docusaurus/plugin-content-docs"; -/** - * Creating a sidebar enables you to: - - create an ordered group of docs - - render a sidebar for each doc of that group - - provide next/previous navigation - - The sidebars can be generated from the filesystem, or explicitly defined here. - - Create as many sidebars as you want. - */ const sidebars: SidebarsConfig = { - // By default, Docusaurus generates a sidebar from the docs folder structure - tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], - - // But you can create a sidebar manually - /* - tutorialSidebar: [ - 'intro', - 'hello', - { - type: 'category', - label: 'Tutorial', - items: ['tutorial-basics/create-a-document'], - }, - ], - */ + tutorialSidebar: [{ type: "autogenerated", dirName: "." }], }; export default sidebars; diff --git a/src/components/fx-converter.tsx b/src/components/fx-converter.tsx index 43658df..cbcd258 100644 --- a/src/components/fx-converter.tsx +++ b/src/components/fx-converter.tsx @@ -1,39 +1,42 @@ -import { useRef, useState } from "react" +import { useRef, useState } from "react"; function float_to_fixedpoint(input: string): string { - console.log(input) - let float = parseFloat(input) - let abs_float = Math.abs(float) - let int = Math.floor(abs_float) + let float = parseFloat(input); + let abs_float = Math.abs(float); + let int = Math.floor(abs_float); if (int > 2 << 51) { - int = 2 << 51 + int = 2 << 51; } - let sign = float < 0 ? "-" : "" - let frac = Math.floor((abs_float % 1) * 4096.0) - let frac_str = "" + let sign = float < 0 ? "-" : ""; + let frac = Math.floor((abs_float % 1) * 4096.0); + let frac_str = ""; if (frac != 0) { - frac_str = "." + frac + frac_str = "." + frac; } - return `${sign}${int}${frac_str}fx` + return `${sign}${int}${frac_str}fx`; } export default function FxConverter() { - const [num, setNum] = useState("2.718") + const [num, setNum] = useState("2.718"); - const outputRef = useRef(null) + const outputRef = useRef(null); return (
- setNum(event.target.value)} /> + setNum(event.target.value)} + /> { - outputRef.current.value = float_to_fixedpoint(num) + outputRef.current.value = float_to_fixedpoint(num); }} />
- ) + ); } diff --git a/src/css/custom.css b/src/css/custom.css index 2bc6a4c..3859140 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -18,7 +18,7 @@ } /* For readability concerns, you should choose a lighter palette in dark mode. */ -[data-theme='dark'] { +[data-theme="dark"] { --ifm-color-primary: #25c2a0; --ifm-color-primary-dark: #21af90; --ifm-color-primary-darker: #1fa588; diff --git a/src/pages/markdown-page.md b/src/pages/markdown-page.md deleted file mode 100644 index 9756c5b..0000000 --- a/src/pages/markdown-page.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Markdown page example ---- - -# Markdown page example - -You don't need React to write simple standalone pages.