add some minimalistic documentation to "more complex" methods
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -43,6 +43,9 @@ public class GameView extends View<GameViewModel> {
|
||||
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<GameViewModel> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows animated damage text at the specified position.
|
||||
*/
|
||||
private void showDamage(Map.Entry<Vector2, Integer> damAndPos) {
|
||||
Vector2 position = damAndPos.getKey();
|
||||
int damage = damAndPos.getValue();
|
||||
|
||||
@@ -28,6 +28,9 @@ public class MenuView extends View<MenuViewModel> {
|
||||
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<MenuViewModel> {
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<MenuViewModel> {
|
||||
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<MenuViewModel> {
|
||||
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<MenuViewModel> {
|
||||
selectMenuItem((Group) menuContentTable.getChild(currentIdx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves selection to the previous menu item.
|
||||
*/
|
||||
@Override
|
||||
public void onUp() {
|
||||
Group menuContentTable = this.selectedItem.getParent();
|
||||
|
||||
Reference in New Issue
Block a user