From e331582663619d9c31d80ec76ff2effc4d525f4d Mon Sep 17 00:00:00 2001 From: Quillraven Date: Mon, 23 Jun 2025 21:21:05 +0200 Subject: [PATCH] add some minimalistic documentation to "more complex" methods --- .../java/io/github/com/quillraven/GdxGame.java | 6 ++++++ .../com/quillraven/screen/LoadingScreen.java | 6 ++++++ .../com/quillraven/system/AnimationSystem.java | 6 ++++++ .../com/quillraven/system/AttackSystem.java | 3 +++ .../com/quillraven/system/CameraSystem.java | 10 +++++++++- .../com/quillraven/system/ControllerSystem.java | 3 +++ .../com/quillraven/system/PhysicSystem.java | 12 ++++++++++++ .../com/quillraven/system/RenderSystem.java | 9 +++++++++ .../com/quillraven/system/TriggerSystem.java | 9 +++++++++ .../quillraven/tiled/TiledAshleyConfigurator.java | 3 +++ .../github/com/quillraven/tiled/TiledService.java | 7 ++++++- .../github/com/quillraven/ui/view/GameView.java | 6 ++++++ .../github/com/quillraven/ui/view/MenuView.java | 15 +++++++++++++++ 13 files changed, 93 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/github/com/quillraven/GdxGame.java b/core/src/main/java/io/github/com/quillraven/GdxGame.java index e657676..8e0a7cb 100644 --- a/core/src/main/java/io/github/com/quillraven/GdxGame.java +++ b/core/src/main/java/io/github/com/quillraven/GdxGame.java @@ -75,6 +75,9 @@ public class GdxGame extends Game { screenCache.remove(screen.getClass()); } + /** + * Renders the current screen with performance monitoring. + */ @Override public void render() { glProfiler.reset(); @@ -94,6 +97,9 @@ public class GdxGame extends Game { super.resize(width, height); } + /** + * Cleans up all game resources and services. + */ @Override public void dispose() { for (Screen screen : screenCache.values()) { diff --git a/core/src/main/java/io/github/com/quillraven/screen/LoadingScreen.java b/core/src/main/java/io/github/com/quillraven/screen/LoadingScreen.java index fe4173a..68162ab 100644 --- a/core/src/main/java/io/github/com/quillraven/screen/LoadingScreen.java +++ b/core/src/main/java/io/github/com/quillraven/screen/LoadingScreen.java @@ -18,6 +18,9 @@ public class LoadingScreen extends ScreenAdapter { this.assetService = game.getAssetService(); } + /** + * Queues all required assets for loading. + */ @Override public void show() { for (AtlasAsset atlasAsset : AtlasAsset.values()) { @@ -29,6 +32,9 @@ public class LoadingScreen extends ScreenAdapter { } } + /** + * Updates asset loading progress and transitions to menu when complete. + */ @Override public void render(float delta) { if (assetService.update()) { diff --git a/core/src/main/java/io/github/com/quillraven/system/AnimationSystem.java b/core/src/main/java/io/github/com/quillraven/system/AnimationSystem.java index 0e432b5..9673860 100644 --- a/core/src/main/java/io/github/com/quillraven/system/AnimationSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/AnimationSystem.java @@ -31,6 +31,9 @@ public class AnimationSystem extends IteratingSystem { this.animationCache = new HashMap<>(); } + /** + * Updates animation state and sets graphic's component region. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Animation2D animation2D = Animation2D.MAPPER.get(entity); @@ -49,6 +52,9 @@ public class AnimationSystem extends IteratingSystem { Graphic.MAPPER.get(entity).setRegion(keyFrame); } + /** + * Updates animation based on direction and type, using cached animations. + */ private void updateAnimation(Animation2D animation2D, FacingDirection direction) { AtlasAsset atlasAsset = animation2D.getAtlasAsset(); String atlasKey = animation2D.getAtlasKey(); diff --git a/core/src/main/java/io/github/com/quillraven/system/AttackSystem.java b/core/src/main/java/io/github/com/quillraven/system/AttackSystem.java index 646d814..6009310 100644 --- a/core/src/main/java/io/github/com/quillraven/system/AttackSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/AttackSystem.java @@ -39,6 +39,9 @@ public class AttackSystem extends IteratingSystem { this.attackDamage = 0f; } + /** + * Processes attack logic including sound effects and damage detection. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Attack attack = Attack.MAPPER.get(entity); diff --git a/core/src/main/java/io/github/com/quillraven/system/CameraSystem.java b/core/src/main/java/io/github/com/quillraven/system/CameraSystem.java index e2e545a..7c8bee1 100644 --- a/core/src/main/java/io/github/com/quillraven/system/CameraSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/CameraSystem.java @@ -27,6 +27,9 @@ public class CameraSystem extends IteratingSystem { this.targetPosition = new Vector2(); } + /** + * Updates camera position with smooth following and boundary constraints. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Transform transform = Transform.MAPPER.get(entity); @@ -39,8 +42,10 @@ public class CameraSystem extends IteratingSystem { camera.position.set(smoothedX, smoothedY, camera.position.z); } + /** + * Calculates target camera position within map boundaries. + */ private void calcTargetPosition(Vector2 entityPosition) { - // Keep the target position within map boundaries float targetX = entityPosition.x; float targetY = entityPosition.y + CAM_OFFSET_Y; float camHalfW = camera.viewportWidth * 0.5f; @@ -58,6 +63,9 @@ public class CameraSystem extends IteratingSystem { this.targetPosition.set(targetX, targetY); } + /** + * Sets up camera for a new map and positions it at the target entity. + */ public void setMap(TiledMap tiledMap) { int width = tiledMap.getProperties().get("width", 0, Integer.class); int tileW = tiledMap.getProperties().get("tilewidth", 0, Integer.class); diff --git a/core/src/main/java/io/github/com/quillraven/system/ControllerSystem.java b/core/src/main/java/io/github/com/quillraven/system/ControllerSystem.java index 7e54b40..7a048e1 100644 --- a/core/src/main/java/io/github/com/quillraven/system/ControllerSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/ControllerSystem.java @@ -18,6 +18,9 @@ public class ControllerSystem extends IteratingSystem { this.game = game; } + /** + * Processes input commands for the entity, handling movement and actions. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Controller controller = Controller.MAPPER.get(entity); diff --git a/core/src/main/java/io/github/com/quillraven/system/PhysicSystem.java b/core/src/main/java/io/github/com/quillraven/system/PhysicSystem.java index e0465e9..9f2ff55 100644 --- a/core/src/main/java/io/github/com/quillraven/system/PhysicSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/PhysicSystem.java @@ -44,6 +44,9 @@ public class PhysicSystem extends IteratingSystem implements EntityListener, Con engine.removeEntityListener(this); } + /** + * Updates physics simulation with fixed timestep and interpolation. + */ @Override public void update(float deltaTime) { this.accumulator += deltaTime; @@ -61,12 +64,18 @@ public class PhysicSystem extends IteratingSystem implements EntityListener, Con } } + /** + * Stores previous position for interpolation. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Physic physic = Physic.MAPPER.get(entity); physic.getPrevPosition().set(physic.getBody().getPosition()); } + /** + * Interpolates entity position between physics steps. + */ private void interpolateEntity(Entity entity, float alpha) { Transform transform = Transform.MAPPER.get(entity); Physic physic = Physic.MAPPER.get(entity); @@ -94,6 +103,9 @@ public class PhysicSystem extends IteratingSystem implements EntityListener, Con } } + /** + * Handles collision detection between entities and triggers. + */ @Override public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); diff --git a/core/src/main/java/io/github/com/quillraven/system/RenderSystem.java b/core/src/main/java/io/github/com/quillraven/system/RenderSystem.java index 52ba40d..50fa8f3 100644 --- a/core/src/main/java/io/github/com/quillraven/system/RenderSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/RenderSystem.java @@ -43,6 +43,9 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable { this.bgdLayers = new ArrayList<>(); } + /** + * Renders the scene with background, entities, and foreground layers. + */ @Override public void update(float deltaTime) { AnimatedTiledMapTile.updateAnimationBaseTime(); @@ -61,6 +64,9 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable { batch.end(); } + /** + * Renders a single entity with its transform and graphic components. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Transform transform = Transform.MAPPER.get(entity); @@ -84,6 +90,9 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable { ); } + /** + * Sets up the map and organizes layers into background and foreground. + */ public void setMap(TiledMap tiledMap) { this.tiledRenderer.setMap(tiledMap); diff --git a/core/src/main/java/io/github/com/quillraven/system/TriggerSystem.java b/core/src/main/java/io/github/com/quillraven/system/TriggerSystem.java index e79f89d..cea8041 100644 --- a/core/src/main/java/io/github/com/quillraven/system/TriggerSystem.java +++ b/core/src/main/java/io/github/com/quillraven/system/TriggerSystem.java @@ -22,6 +22,9 @@ public class TriggerSystem extends IteratingSystem { this.audioService = audioService; } + /** + * Processes triggered entities and fires appropriate trigger effects. + */ @Override protected void processEntity(Entity entity, float deltaTime) { Trigger trigger = Trigger.MAPPER.get(entity); @@ -41,6 +44,9 @@ public class TriggerSystem extends IteratingSystem { return null; } + /** + * Routes trigger events to appropriate handlers based on trigger name. + */ private void fireTrigger(String triggerName, Entity triggeringEntity) { switch (triggerName) { case "trap_trigger" -> trapTrigger(triggeringEntity); @@ -48,6 +54,9 @@ public class TriggerSystem extends IteratingSystem { } } + /** + * Handles trap trigger effects including animation and damage. + */ private void trapTrigger(Entity triggeringEntity) { Entity trapEntity = getByTiledId(15); if (trapEntity != null) { diff --git a/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleyConfigurator.java b/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleyConfigurator.java index a729403..c973633 100644 --- a/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleyConfigurator.java +++ b/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleyConfigurator.java @@ -91,6 +91,9 @@ public class TiledAshleyConfigurator { } } + /** + * Creates and configures an entity from a Tiled map object with all necessary components. + */ public void onLoadObject(TiledMapTileMapObject tileMapObject) { Entity entity = this.engine.createEntity(); TiledMapTile tile = tileMapObject.getTile(); diff --git a/core/src/main/java/io/github/com/quillraven/tiled/TiledService.java b/core/src/main/java/io/github/com/quillraven/tiled/TiledService.java index 6cf4d83..4df243a 100644 --- a/core/src/main/java/io/github/com/quillraven/tiled/TiledService.java +++ b/core/src/main/java/io/github/com/quillraven/tiled/TiledService.java @@ -75,6 +75,9 @@ public class TiledService { this.loadTileConsumer = loadTileConsumer; } + /** + * Loads all map objects from different layers and creates map collision boundaries. + */ public void loadMapObjects(TiledMap tiledMap) { for (MapLayer layer : tiledMap.getLayers()) { if (layer instanceof TiledMapTileLayer tileLayer) { @@ -89,8 +92,10 @@ public class TiledService { spawnMapBoundary(tiledMap); } + /** + * Creates physics boundaries around the map edges. + */ private void spawnMapBoundary(TiledMap tiledMap) { - // create four boxes for the map boundary (left, right, bottom and top edge) int width = tiledMap.getProperties().get("width", 0, Integer.class); int tileW = tiledMap.getProperties().get("tilewidth", 0, Integer.class); int height = tiledMap.getProperties().get("height", 0, Integer.class); diff --git a/core/src/main/java/io/github/com/quillraven/ui/view/GameView.java b/core/src/main/java/io/github/com/quillraven/ui/view/GameView.java index 2f01bc8..a9384b2 100644 --- a/core/src/main/java/io/github/com/quillraven/ui/view/GameView.java +++ b/core/src/main/java/io/github/com/quillraven/ui/view/GameView.java @@ -43,6 +43,9 @@ public class GameView extends View { add(horizontalGroup); } + /** + * Updates the life display with appropriate heart icons. + */ private void updateLife(int lifePoints) { lifeGroup.clear(); @@ -57,6 +60,9 @@ public class GameView extends View { } } + /** + * Shows animated damage text at the specified position. + */ private void showDamage(Map.Entry damAndPos) { Vector2 position = damAndPos.getKey(); int damage = damAndPos.getValue(); diff --git a/core/src/main/java/io/github/com/quillraven/ui/view/MenuView.java b/core/src/main/java/io/github/com/quillraven/ui/view/MenuView.java index 0fbecb9..bb145fd 100644 --- a/core/src/main/java/io/github/com/quillraven/ui/view/MenuView.java +++ b/core/src/main/java/io/github/com/quillraven/ui/view/MenuView.java @@ -28,6 +28,9 @@ public class MenuView extends View { selectMenuItem(this.selectedItem); } + /** + * Selects a menu item and animates the selection indicator. + */ private void selectMenuItem(Group menuItem) { if (selectionImg.getParent() != null) { selectionImg.getParent().removeActor(selectionImg); @@ -54,6 +57,9 @@ public class MenuView extends View { ))); } + /** + * Sets up the main UI layout with banner and menu content. + */ @Override protected void setupUI() { setFillParent(true); @@ -68,6 +74,9 @@ public class MenuView extends View { add(label).padRight(5.0f).padBottom(5f).expand().align(Align.bottomRight); } + /** + * Creates the menu content with buttons and volume sliders. + */ private void setupMenuContent() { Table contentTable = new Table(); contentTable.setBackground(skin.getDrawable("frame")); @@ -114,6 +123,9 @@ public class MenuView extends View { return slider; } + /** + * Moves selection to the next menu item. + */ @Override public void onDown() { Group menuContentTable = this.selectedItem.getParent(); @@ -127,6 +139,9 @@ public class MenuView extends View { selectMenuItem((Group) menuContentTable.getChild(currentIdx)); } + /** + * Moves selection to the previous menu item. + */ @Override public void onUp() { Group menuContentTable = this.selectedItem.getParent();