forked from dcatanzaro/aoweb
-
Notifications
You must be signed in to change notification settings - Fork 34
feat(core): implement core game data sync, protocol package, CI matrix, and map toolchain (#28, #11, #27, #23, #10, #20) #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Simultech369
wants to merge
4
commits into
Bitcoindefi:main
Choose a base branch
from
Simultech369:feat/grantfox-bounty-batch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7444aa
feat(core): implement GrantFox bounty batch (#28, #11, #27, #23, #10,β¦
Simultech369 f5a7b0c
Merge upstream main into feat/grantfox-bounty-batch-1
Simultech369 ca1bced
fix(map-toolchain): address review feedback on VB6 encoding, atomic eβ¦
Simultech369 482cc84
Fix paired map exit lock ordering
Simultech369 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { z } from "zod"; | ||
|
|
||
| export type TileExit = { | ||
| map: number; | ||
| x: number; | ||
| y: number; | ||
| }; | ||
|
|
||
| export type TileExitConfig = TileExit | { destinations: TileExit[] }; | ||
|
|
||
| export type SpecialsJson = { | ||
| id: number; | ||
| exits: Record<string, TileExitConfig>; | ||
| objects: Record<string, { objIndex: number; amount: number }>; | ||
| npcs: Record<string, number>; | ||
| triggers: Record<string, number>; | ||
| }; | ||
|
|
||
| const MAPS_SOURCE_DIR = path.resolve(__dirname, "../../../server/mapas_source"); | ||
|
|
||
| function getMapSpecialsPath(mapNum: number): string { | ||
| return path.join(MAPS_SOURCE_DIR, `mapa_${mapNum}`, "specials.json"); | ||
| } | ||
|
|
||
| function readMapSpecials(mapNum: number): SpecialsJson { | ||
| const filePath = getMapSpecialsPath(mapNum); | ||
| if (!fs.existsSync(filePath)) { | ||
| return { | ||
| id: mapNum, | ||
| exits: {}, | ||
| objects: {}, | ||
| npcs: {}, | ||
| triggers: {}, | ||
| }; | ||
| } | ||
|
|
||
| try { | ||
| const raw = fs.readFileSync(filePath, "utf8"); | ||
| return JSON.parse(raw) as SpecialsJson; | ||
| } catch { | ||
| return { | ||
| id: mapNum, | ||
| exits: {}, | ||
| objects: {}, | ||
| npcs: {}, | ||
| triggers: {}, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| function writeMapSpecials(mapNum: number, data: SpecialsJson): void { | ||
| const filePath = getMapSpecialsPath(mapNum); | ||
| fs.mkdirSync(path.dirname(filePath), { recursive: true }); | ||
| fs.writeFileSync(filePath, JSON.stringify(data), "utf8"); | ||
| } | ||
|
|
||
| export const upsertExitSchema = z.object({ | ||
| destMap: z.number().int().positive(), | ||
| destX: z.number().int().min(1).max(100), | ||
| destY: z.number().int().min(1).max(100), | ||
| createPaired: z.boolean().optional().default(false), | ||
| }); | ||
|
|
||
| export type UpsertExitInput = z.infer<typeof upsertExitSchema>; | ||
|
|
||
| export async function getMapExits(mapNum: number): Promise<{ mapNum: number; exits: Record<string, TileExitConfig> }> { | ||
| const specials = readMapSpecials(mapNum); | ||
| return { | ||
| mapNum, | ||
| exits: specials.exits ?? {}, | ||
| }; | ||
| } | ||
|
|
||
| export async function upsertMapExit( | ||
| mapNum: number, | ||
| x: number, | ||
| y: number, | ||
| input: UpsertExitInput, | ||
| ): Promise<{ | ||
| mapNum: number; | ||
| x: number; | ||
| y: number; | ||
| exit: TileExit; | ||
| pairedExitCreated: boolean; | ||
| }> { | ||
| const coordKey = `${x},${y}`; | ||
| const exitTarget: TileExit = { | ||
| map: input.destMap, | ||
|
gitar-bot[bot] marked this conversation as resolved.
Outdated
|
||
| x: input.destX, | ||
| y: input.destY, | ||
| }; | ||
|
|
||
| const sourceSpecials = readMapSpecials(mapNum); | ||
| if (!sourceSpecials.exits) { | ||
| sourceSpecials.exits = {}; | ||
| } | ||
| sourceSpecials.exits[coordKey] = exitTarget; | ||
| writeMapSpecials(mapNum, sourceSpecials); | ||
|
|
||
| let pairedExitCreated = false; | ||
|
|
||
| if (input.createPaired) { | ||
| const destSpecials = readMapSpecials(input.destMap); | ||
| if (!destSpecials.exits) { | ||
| destSpecials.exits = {}; | ||
| } | ||
| const destCoordKey = `${input.destX},${input.destY}`; | ||
| destSpecials.exits[destCoordKey] = { | ||
| map: mapNum, | ||
| x, | ||
| y, | ||
| }; | ||
| writeMapSpecials(input.destMap, destSpecials); | ||
| pairedExitCreated = true; | ||
| } | ||
|
|
||
| return { | ||
| mapNum, | ||
| x, | ||
| y, | ||
| exit: exitTarget, | ||
| pairedExitCreated, | ||
| }; | ||
| } | ||
|
|
||
| export async function deleteMapExit( | ||
| mapNum: number, | ||
| x: number, | ||
| y: number, | ||
| deletePaired = false, | ||
| ): Promise<{ | ||
| mapNum: number; | ||
| x: number; | ||
| y: number; | ||
| deleted: boolean; | ||
| pairedExitDeleted: boolean; | ||
| }> { | ||
| const coordKey = `${x},${y}`; | ||
| const sourceSpecials = readMapSpecials(mapNum); | ||
| const existingExit = sourceSpecials.exits?.[coordKey]; | ||
|
|
||
| if (!existingExit) { | ||
| return { | ||
| mapNum, | ||
| x, | ||
| y, | ||
| deleted: false, | ||
| pairedExitDeleted: false, | ||
| }; | ||
| } | ||
|
|
||
| delete sourceSpecials.exits[coordKey]; | ||
| writeMapSpecials(mapNum, sourceSpecials); | ||
|
|
||
| let pairedExitDeleted = false; | ||
|
|
||
| if (deletePaired && "map" in existingExit) { | ||
| const destMap = existingExit.map; | ||
| const destX = existingExit.x; | ||
| const destY = existingExit.y; | ||
| const destCoordKey = `${destX},${destY}`; | ||
|
|
||
| const destSpecials = readMapSpecials(destMap); | ||
| if (destSpecials.exits?.[destCoordKey]) { | ||
| delete destSpecials.exits[destCoordKey]; | ||
| writeMapSpecials(destMap, destSpecials); | ||
| pairedExitDeleted = true; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| mapNum, | ||
| x, | ||
| y, | ||
| deleted: true, | ||
| pairedExitDeleted, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.