fix: fix clipping display issues and add layer support#11
fix: fix clipping display issues and add layer support#11jatoothless wants to merge 4 commits intomainfrom
Conversation
jatoothless
commented
Mar 9, 2026
- Naprawiłam clippowanie przez podłoge
- Lekko poprawiłam rysowanie mapy
- Dodałam warstwy
bnszky
left a comment
There was a problem hiding this comment.
Super, właśnie też nad tym się zastanawiałem, żeby przenieść tworzenie mapy do osobnej klasy. Odnośnie zmian z dodawaniem nowym obiektów i refactoringiem zmiany są tutaj: refactor/add-srp-and-ocp. To myślę, że można zmergować
|
Na mainie są teraz jeszcze kable, więc możesz również je dodać do warst i wtedy rebase |
fdfd652 to
dc5c535
Compare
bnszky
left a comment
There was a problem hiding this comment.
Stwórzmy strukturę danych, która pozwoli w łatwy sposób dodawać nowe layery i priorytetować ich kolejność, nazwy powinny znaleźć się w pliku globalnym np constants/global
Tam tworzymy np. listę:
layers = ["background", "floor_decoys", "entities", "wall decoys", "effects"]
automatycznie indeksy oznaczają kolejność i setDepth
Wyobraźmy sobie sytuację, że chcemy dodać nową warstwę np. "entities2" i wiemy, że powinna znaleźć się po "entities". Wtedy w tej liście po prostu wstawimy "entities2" i displayer sam to posortuje.
W kodzie dodamy wtedy tylko add(object, "entities2") i tyle
W tym momencie musielibyśmy zmieniać wiele linijek żeby wprowadzić nową warstwę
CEL: dodawać warstwę tylko w liście layers
I tak dużo już się udało zrobić. Ta zmiana zaoszczędzi później czas i odchudzi jeszcze bardziej kod
client/src/phaser/lib/display.ts
Outdated
| const TILE_MAPPING: Record< | ||
| string, | ||
| { frame: number; isTall?: boolean; frameSecond?: number } | ||
| > = { | ||
| w1t: { frame: 0, frameSecond: 10, isTall: true }, | ||
| w1: { frame: 0 }, | ||
| w13: { frame: 9 }, | ||
| w2t: { frame: 2, frameSecond: 4, isTall: true }, | ||
| w2: { frame: 2 }, | ||
| w3t: { frame: 3, frameSecond: 4, isTall: true }, | ||
| w3: { frame: 3 }, | ||
| w21: { frame: 8 }, | ||
| f1: { frame: 6 }, | ||
| }; |
There was a problem hiding this comment.
Usuń TILE_MAPPING i importuj z constants/blocks. Tam już jest
client/src/phaser/lib/display.ts
Outdated
| private BACKGROUND: Phaser.GameObjects.Layer; | ||
| private FLOOR_DECOYS: Phaser.GameObjects.Layer; | ||
| private ENTITIES: Phaser.GameObjects.Layer; | ||
| private WALL_DECOYS: Phaser.GameObjects.Layer; | ||
| private EFFECTS: Phaser.GameObjects.Layer; |
There was a problem hiding this comment.
Zamiast tego można napisać
private LAYERS: Phaser.GameObjects.Layer[]
client/src/phaser/lib/display.ts
Outdated
| layer: | ||
| | "background" | ||
| | "floor decoys" | ||
| | "entities" | ||
| | "wall decoys" | ||
| | "effects", |
There was a problem hiding this comment.
stwórz interface LayerNames z tymi nowymi nazwami i wtedy wszędzie:
layer: LayerNames
client/src/phaser/lib/display.ts
Outdated
| layer: //Layery są tu poukładane od najgłębszego do najpłytszego | ||
| | "background" //ściany i podłoga | ||
| | "floor decoys" //wszystko co na podłodze - venty, guziki, kable | ||
| | "entities" //gracz kapibara i rzeczy które "stoją na podłodze" | ||
| | "wall decoys" //rzeczy typu drzwi | ||
| | "effects", //efekty - np dymki |
| layer: | ||
| | "background" | ||
| | "floor decoys" | ||
| | "entities" | ||
| | "wall decoys" | ||
| | "effects", |
|
i jeszcze zamiast stringów najlepiej zrobić słownik, bo będzie problem jak zmienimy "wall_decoys" na "walls_decoy", więc add(object, LayerNamesEnum.BACKGROUND) *Komentarze po angielsku |
bnszky
left a comment
There was a problem hiding this comment.
Właśnie o to chodziło, jeszcze tylko dopisałem, żeby nie używać hardkodowanych stringów w kodzie, tylko stworzyć jakiś słownik, gdyby ktoś się pomylił, wpisując np. "entitties" zamiast "entities". Aktualnie linter nam tego nie podświetli z taką literówką, ale kod nie będzie poprawnie działał.
Nie musisz tego poprawiać, mogę to zrobić ja już w osobnym branchu, więc daje approve
|
|
||
| for (const crate of message.crates) { | ||
| this.spawnEntity(this.crates, Crate, crate); | ||
| this.spawnEntity(this.crates, Crate, crate, "entities"); |
There was a problem hiding this comment.
| this.spawnEntity(this.crates, Crate, crate, "entities"); | |
| this.spawnEntity(this.crates, Crate, crate, LAYER_NAMES_GLOBAL.ENTITIES); |
|
|
||
| if (tileType !== "") { | ||
| this.layerMap | ||
| .get("background") |
There was a problem hiding this comment.
| .get("background") | |
| .get(LAYER_NAMES_GLOBAL.BACKGROUND) |
| export const LAYERS = [ //Layers in order of deepest to shallowest | ||
| "background", //Floor tiles and wall tiles | ||
| "floor decoys", //Things on the floor such as vents or buttons | ||
| "entities", //Players, enemies and things above floor decoys like lasers | ||
| "wall decoys", //Upper parts of walls and doord | ||
| "effects", //Extra effects rendered on top like speech bubbles | ||
| ] as const; |
There was a problem hiding this comment.
| export const LAYERS = [ //Layers in order of deepest to shallowest | |
| "background", //Floor tiles and wall tiles | |
| "floor decoys", //Things on the floor such as vents or buttons | |
| "entities", //Players, enemies and things above floor decoys like lasers | |
| "wall decoys", //Upper parts of walls and doord | |
| "effects", //Extra effects rendered on top like speech bubbles | |
| ] as const; | |
| export const LAYER_NAMES_GLOBAL = { | |
| BACKGROUND: "background", | |
| FLOOR_DECOYS: "floor decoys", | |
| ENTITIES: "entities", | |
| WALL_DECOYS: "wall decoys", | |
| EFFECTS: "effects", | |
| } | |
| as const; | |
| export const LAYERS = [ | |
| //Layers in order of deepest to shallowest | |
| LAYER_NAMES_GLOBAL.BACKGROUND, //Floor tiles and wall tiles | |
| LAYER_NAMES_GLOBAL.FLOOR_DECOYS, //Things on the floor such as vents or buttons | |
| LAYER_NAMES_GLOBAL.ENTITIES, //Players, enemies and things above floor decoys like lasers | |
| LAYER_NAMES_GLOBAL.WALL_DECOYS, //Upper parts of walls and doord | |
| LAYER_NAMES_GLOBAL.EFFECTS, //Extra effects rendered on top like speech bubbles | |
| ] as const; |
| layer: | ||
| | "background" | ||
| | "floor decoys" | ||
| | "entities" | ||
| | "wall decoys" | ||
| | "effects", |
There was a problem hiding this comment.
| layer: | |
| | "background" | |
| | "floor decoys" | |
| | "entities" | |
| | "wall decoys" | |
| | "effects", | |
| layer: LayerNames |