Skip to content

Commit

Permalink
chore: remove portal extension and add portal connections script (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeilin authored Dec 30, 2024
2 parents beb21cb + bcbf84f commit 6d3a586
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 201 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview",
"generate-map-data": "tsx src/scripts/fetch-map-data.ts"
"generate-map-data": "tsx src/scripts/fetch-map-data.ts",
"add-connection": "tsx scripts/add-map-connection.ts"
},
"dependencies": {
"@tanstack/react-query": "^5.62.10",
Expand Down
62 changes: 59 additions & 3 deletions public/map-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,12 @@
"portalName": "out00",
"x": -221,
"y": 82
},
{
"toMapId": 200090010,
"portalName": "portal00",
"x": 0,
"y": 0
}
]
},
Expand Down Expand Up @@ -11926,6 +11932,18 @@
"portalName": "west00",
"x": -1557,
"y": 82
},
{
"toMapId": 200000112,
"portalName": "portal00",
"x": 800,
"y": 0
},
{
"toMapId": 200000121,
"portalName": "portal00",
"x": 800,
"y": 0
}
]
},
Expand Down Expand Up @@ -11971,6 +11989,12 @@
"portalName": "h002",
"x": -18,
"y": -455
},
{
"toMapId": 200090000,
"portalName": "portal00",
"x": 0,
"y": -1
}
]
},
Expand All @@ -11984,14 +12008,27 @@
"portalName": "west00",
"x": -420,
"y": 139
},
{
"toMapId": 200000122,
"portalName": "portal00",
"x": 0,
"y": -600
}
]
},
"200000122": {
"id": 200000122,
"name": "Before the Departure <Ludibrium>",
"streetName": "Orbis",
"connections": []
"connections": [
{
"toMapId": 200090100,
"portalName": "portal00",
"x": 0,
"y": 0
}
]
},
"200000130": {
"id": 200000130,
Expand Down Expand Up @@ -13135,6 +13172,12 @@
"portalName": "h002_1",
"x": -93,
"y": -617
},
{
"toMapId": 101000300,
"portalName": "portal00",
"x": 0,
"y": 0
}
]
},
Expand Down Expand Up @@ -13185,6 +13228,12 @@
"portalName": "h002_1",
"x": -13,
"y": -625
},
{
"toMapId": 200000100,
"portalName": "portal00",
"x": 0,
"y": 0
}
]
},
Expand Down Expand Up @@ -16574,7 +16623,14 @@
"id": 200090100,
"name": "Ludibrium",
"streetName": "On a Voyage",
"connections": []
"connections": [
{
"toMapId": 220000000,
"portalName": "portal00",
"x": 0,
"y": 0
}
]
},
"200090110": {
"id": 200090110,
Expand Down Expand Up @@ -55631,4 +55687,4 @@
}
]
}
}
}
83 changes: 0 additions & 83 deletions public/portal-extensions.json

This file was deleted.

149 changes: 149 additions & 0 deletions scripts/add-map-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/env tsx

import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { createInterface } from 'readline';

type Direction = 'left' | 'right' | 'up' | 'down' | '';

interface MapConnection {
toMapId: number;
portalName: string;
x: number;
y: number;
}

interface MapNode {
id: number;
name: string;
streetName: string;
connections: MapConnection[];
}

interface MapGraph {
[key: string]: MapNode;
}

const rl = createInterface({
input: process.stdin,
output: process.stdout
});

const question = (query: string): Promise<string> => {
return new Promise((resolve) => {
rl.question(query, resolve);
});
};

interface MapWithDirection {
mapId: string;
direction: Direction;
}

function getCoordinatesForDirection(direction: Direction): { x: number; y: number } {
// These values are typical portal positions in MapleStory maps
switch (direction) {
case 'left':
return { x: -800, y: 0 };
case 'right':
return { x: 800, y: 0 };
case 'up':
return { x: 0, y: -600 };
case 'down':
return { x: 0, y: 600 };
default:
return { x: 0, y: 0 };
}
}

async function getDirection(): Promise<Direction> {
const input = (await question('Enter direction (left/right/up/down) or press Enter for no direction: ')).toLowerCase();

if (input === '') return '';
if (['left', 'right', 'up', 'down'].includes(input)) {
return input as Direction;
}
console.log('Invalid direction. Please enter left, right, up, down, or press Enter for no direction.');
return getDirection();
}

async function main() {
// Read the map graph
const mapGraphPath = join(process.cwd(), 'public', 'map-graph.json');
const mapGraph: MapGraph = JSON.parse(readFileSync(mapGraphPath, 'utf-8'));

console.log('Welcome to the Map Connection Tool!\n');

// Get source map ID
const sourceMapId = await question('Enter the source map ID (e.g., 101000300): ');
if (!mapGraph[sourceMapId]) {
console.error('Source map not found!');
process.exit(1);
}
console.log(`Selected: ${mapGraph[sourceMapId].name} (${mapGraph[sourceMapId].streetName})\n`);

// Get target map ID
const targetMapId = await question('Enter the target map ID (e.g., 200000100): ');
if (!mapGraph[targetMapId]) {
console.error('Target map not found!');
process.exit(1);
}
console.log(`Selected: ${mapGraph[targetMapId].name} (${mapGraph[targetMapId].streetName})\n`);

// Get intermediate maps with directions
const intermediateMaps: MapWithDirection[] = [];
console.log('\nEnter intermediate map IDs one by one (press Enter without input when done):');

while (true) {
const intermediateMapId = await question('\nEnter intermediate map ID (or press Enter to finish): ');
if (!intermediateMapId) break;

if (!mapGraph[intermediateMapId]) {
console.log('Map not found, try again.');
continue;
}

const direction = await getDirection();
console.log(`Added: ${mapGraph[intermediateMapId].name} (${mapGraph[intermediateMapId].streetName}) - Direction: ${direction || 'none'}`);
intermediateMaps.push({ mapId: intermediateMapId, direction });
}

// Get final direction to target
console.log('\nEnter direction for the final connection:');
const finalDirection = await getDirection();

// Create connections
const allMaps = [
{ mapId: sourceMapId, direction: '' }, // First map doesn't need a direction
...intermediateMaps,
{ mapId: targetMapId, direction: finalDirection }
];

// Connect each map to the next one in sequence
for (let i = 0; i < allMaps.length - 1; i++) {
const currentMapId = allMaps[i].mapId;
const nextMapId = allMaps[i + 1].mapId;
const direction = allMaps[i + 1].direction;

// Add connection to next map if it doesn't exist
if (!mapGraph[currentMapId].connections.some(conn => conn.toMapId === Number(nextMapId))) {
const { x, y } = getCoordinatesForDirection(direction);

mapGraph[currentMapId].connections.push({
toMapId: Number(nextMapId),
portalName: "portal00", // Default portal name
x,
y
});
console.log(`Added connection: ${mapGraph[currentMapId].name}${mapGraph[nextMapId].name} ${direction ? `(${direction})` : ''}`);
}
}

// Save the updated map graph
writeFileSync(mapGraphPath, JSON.stringify(mapGraph, null, 2));
console.log('\nConnections have been added successfully!');

rl.close();
}

main().catch(console.error);
Loading

0 comments on commit 6d3a586

Please sign in to comment.