chore: import MCTF services

- Added all seven issued service trees without omissions.
- Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
TakuyaYagam1 committed 2026-11-29 12:25:29 +03:00
commit 13f936bee9
1222 files changed
+21280

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
const API_BASE = '/api';
async function request(path, options = {}) {
const token = localStorage.getItem('delamain_token');
const headers = { 'Content-Type': 'application/json' };
if (token) headers['Authorization'] = `Bearer ${token}`;
const resp = await fetch(`${API_BASE}${path}`, {
...options,
headers,
});
if (!resp.ok && resp.status !== 400 && resp.status !== 403 && resp.status !== 404) {
const body = await resp.json().catch(() => ({}));
throw new Error(body.error || `Request failed: ${resp.status}`);
}
return resp.json();
}
const api = {
request,
login: (username, password) =>
request('/login', { method: 'POST', body: JSON.stringify({ username, password }) }),
createUser: (username, password) =>
request('/users', { method: 'POST', body: JSON.stringify({ username, password }) }),
createTrip: (tripData) =>
request('/trips', { method: 'POST', body: JSON.stringify(tripData) }),
getTrip: (tripId) => request(`/trips/${tripId}`),
getAllTrips: () => request('/trips'),
getVersions: (tripId) => request(`/trips/${tripId}/versions`),
createPackage: (tripId) =>
request('/packages', { method: 'POST', body: JSON.stringify({ trip_id: tripId }) }),
estimate: (fromX, fromY, toX, toY, cls) =>
request('/estimate', {
method: 'POST',
body: JSON.stringify({ from_x: fromX, from_y: fromY, to_x: toX, to_y: toY, class: cls }),
}),
bookRide: (payload) => request('/trips', { method: 'POST', body: JSON.stringify(payload) }),
};
+271
View File
@@ -0,0 +1,271 @@
const CLASSES = ['Economy', 'Business', 'Excelsior'];
const app = {
user: null,
estimates: {},
selectedClass: null,
booking: false,
estimateSeq: 0,
init: () => {
app.user = {
name: localStorage.getItem('delamain_username'),
token: localStorage.getItem('delamain_token'),
};
app.bindEvents();
app.updateAuthUI();
app.loadTrips();
},
updateAuthUI: () => {
const logged = !!(app.user && app.user.name);
document.getElementById('btn-login').style.display = logged ? 'none' : 'block';
document.getElementById('btn-logout').style.display = logged ? 'block' : 'none';
document.getElementById('auth-hello').textContent = logged ? `Welcome, ${app.user.name}` : '';
},
bindEvents: () => {
document.querySelectorAll('.nav-btn').forEach((btn) => {
btn.addEventListener('click', () => app.switchSection(btn.dataset.section));
});
document.querySelector('.brand').addEventListener('click', () => app.switchSection('section-rides'));
document.querySelectorAll('.close').forEach((c) =>
c.addEventListener('click', () => utils.hideModal(c.closest('.modal').id)));
window.addEventListener('click', (e) => {
if (e.target.classList.contains('modal')) utils.hideModal(e.target.id);
});
document.getElementById('btn-login').addEventListener('click', () => utils.showModal('login-modal'));
document.getElementById('btn-logout').addEventListener('click', app.logout);
document.getElementById('btn-register').addEventListener('click', app.register);
document.getElementById('login-form').addEventListener('submit', app.login);
document.getElementById('btn-refresh-trips').addEventListener('click', app.loadTrips);
document.getElementById('btn-book').addEventListener('click', app.bookRide);
document.getElementById('btn-new-ride').addEventListener('click', app.newRide);
document.getElementById('trips-list').addEventListener('click', (e) => {
const btn = e.target.closest('button[data-act]');
if (!btn) return;
const id = btn.dataset.id;
if (btn.dataset.act === 'view') app.showTripDetails(id);
if (btn.dataset.act === 'versions') app.showVersions(id);
if (btn.dataset.act === 'export') app.exportTrip(id);
});
NightCityMap.init(document.getElementById('nc-map'), app.onPointsChanged);
},
switchSection: (id) => {
document.querySelectorAll('.nav-btn').forEach((b) => b.classList.toggle('active', b.dataset.section === id));
document.querySelectorAll('.section').forEach((s) => s.classList.toggle('active', s.id === id));
if (id === 'section-trips') app.loadTrips();
if (id === 'section-rides') window.setTimeout(() => NightCityMap.refresh(), 0);
},
onPointsChanged: async ({ A, B }) => {
const estimateBlock = document.getElementById('estimate-block');
const estimateLoading = document.getElementById('estimate-loading');
const noPoints = document.getElementById('no-points');
const booked = document.getElementById('booked-block');
const pickup = document.getElementById('pickup-display');
const destination = document.getElementById('destination-display');
const hint = document.getElementById('map-hint-text');
const seq = ++app.estimateSeq;
pickup.textContent = A ? A.name : 'NOT SELECTED';
destination.textContent = B ? B.name : 'NOT SELECTED';
pickup.classList.toggle('is-set', !!A);
destination.classList.toggle('is-set', !!B);
hint.textContent = !A ? 'SET PICKUP POINT' : !B ? 'SET DESTINATION' : 'CLICK TO START A NEW ROUTE';
app.estimates = {};
app.selectedClass = null;
document.getElementById('btn-book').disabled = true;
if (!A || !B) {
estimateBlock.style.display = 'none';
estimateLoading.style.display = 'none';
booked.style.display = 'none';
noPoints.style.display = 'block';
return;
}
booked.style.display = 'none';
noPoints.style.display = 'none';
estimateBlock.style.display = 'none';
estimateLoading.style.display = 'block';
document.getElementById('route-summary').textContent = `${A.name} → ${B.name}`;
const results = await Promise.all(
CLASSES.map((cls) => api.estimate(A.x, A.y, B.x, B.y, cls).catch(() => null))
);
if (seq !== app.estimateSeq) return;
estimateLoading.style.display = 'none';
estimateBlock.style.display = 'block';
const container = document.getElementById('class-cards');
container.innerHTML = '';
results.forEach((r, i) => {
if (!r || r.status !== 0) return;
app.estimates[CLASSES[i]] = r;
const card = document.createElement('div');
card.className = 'class-card';
card.dataset.cls = CLASSES[i];
const serviceNames = ['Standard', 'Executive', 'Excelsior'];
card.innerHTML = `
<div class="class-name">${serviceNames[i]}</div>
<div class="class-meta">${r.duration_min} min · ${r.distance_km} km</div>
<div class="class-price">${r.price} ¢</div>`;
card.addEventListener('click', () => {
app.selectedClass = CLASSES[i];
container.querySelectorAll('.class-card').forEach((c) =>
c.classList.toggle('selected', c.dataset.cls === CLASSES[i]));
document.getElementById('btn-book').disabled = app.booking;
});
container.appendChild(card);
});
},
bookRide: async () => {
const { A, B } = NightCityMap.points;
const cls = app.selectedClass;
if (!A || !B || !cls || app.booking) return;
app.booking = true;
document.getElementById('btn-book').disabled = true;
try {
const resp = await api.bookRide({
origin: A.name,
destination: B.name,
from_x: A.x, from_y: A.y,
to_x: B.x, to_y: B.y,
class: cls,
stops: [A.name, B.name],
instruction: document.getElementById('ride-instruction').value,
});
const est = app.estimates[cls] || {};
document.getElementById('estimate-block').style.display = 'none';
const booked = document.getElementById('booked-block');
booked.style.display = 'block';
document.getElementById('booked-card').innerHTML = `
<div class="booked-id">${utils.escapeHtml(resp.trip_id)}</div>
<div class="booked-route">${utils.escapeHtml(A.name)} → ${utils.escapeHtml(B.name)}</div>
<div class="booked-meta">${cls} · ${est.duration_min || '?'} min · ${est.price || '?'} ¢</div>
<div class="booked-driver">Delamain cab #${Math.floor(Math.random() * 900 + 100)} is on the way</div>
<div class="dim mono">instruction version: ${utils.escapeHtml(resp.version_token || '')}</div>`;
utils.notify(`Ride ${resp.trip_id} booked!`);
} catch (err) {
utils.showError(err);
document.getElementById('btn-book').disabled = false;
} finally {
app.booking = false;
}
},
newRide: () => {
NightCityMap.reset();
document.getElementById('booked-block').style.display = 'none';
document.getElementById('ride-instruction').value = '';
utils.notify('Route cleared');
},
loadTrips: async () => {
const list = document.getElementById('trips-list');
try {
const resp = await api.getAllTrips();
list.innerHTML = '';
if (resp.trips && resp.trips.length) {
resp.trips.forEach((t) => list.appendChild(utils.tripCard(t)));
} else {
utils.empty('trips-list', 'No rides yet. Book your first Delamain ride!');
}
} catch (err) {
utils.empty('trips-list', 'Failed to load trips. Is the service running?');
}
},
showTripDetails: async (tripId) => {
try {
const trip = await api.getTrip(tripId);
const stops = (trip.stops || [])
.map((s, i) => `${i + 1}. ${s.name} (${Math.round(s.x)},${Math.round(s.y)})${s.is_pickup ? ' — pickup' : ''}`)
.join('\n');
alert(
`Ride ${trip.trip_id}\nClass: ${trip.trip.class}\nStatus: ${trip.trip.status}\n\n` +
`Route:\n${stops}\n\nPrivate instruction:\n${trip.instruction}\n\nVersion token: ${trip.version_token}`
);
} catch (err) {
utils.showError(err);
}
},
showVersions: async (tripId) => {
try {
const resp = await api.getVersions(tripId);
const rows = (resp.versions || [])
.map((v) => `${v.version_token} ${v.size}b ${utils.formatDate(v.created_at)}`)
.join('\n');
alert(`Instruction versions for ${tripId}:\n\n${rows || '(none)'}`);
} catch (err) {
utils.showError(err);
}
},
exportTrip: async (tripId) => {
try {
const pkg = await api.createPackage(tripId);
const rows = (pkg.notes || []).map((n) => {
if (n.skipped) {
return `<div class="trip-detail"><span class="label">${utils.escapeHtml(n.source || 'note')}</span><span class="error-text">${utils.escapeHtml(n.skipped)}</span></div>`;
}
return `<div class="trip-detail"><span class="label">Private instruction</span><span class="mono">${utils.escapeHtml(n.data || '')}</span></div>`;
}).join('');
document.getElementById('export-result').innerHTML = rows || '<div class="empty">No note segments</div>';
utils.showModal('export-modal');
} catch (err) {
utils.showError(err);
}
},
login: async (e) => {
e.preventDefault();
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
try {
const resp = await api.login(username, password);
app.user = { name: resp.username, token: resp.token };
localStorage.setItem('delamain_username', resp.username);
localStorage.setItem('delamain_token', resp.token);
utils.hideModal('login-modal');
app.updateAuthUI();
utils.notify(`Welcome back, ${resp.username}! Ride in style.`);
app.loadTrips();
} catch (err) {
utils.showError(err);
}
},
register: async () => {
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
if (!username || !password) return utils.notify('Enter username and password', 'error');
try {
await api.createUser(username, password);
utils.notify('Account created, logging in...');
await app.login({ preventDefault: () => {} });
} catch (err) {
utils.showError(err);
}
},
logout: () => {
app.user = null;
localStorage.removeItem('delamain_username');
localStorage.removeItem('delamain_token');
app.updateAuthUI();
utils.notify('Logged out');
},
};
document.addEventListener('DOMContentLoaded', app.init);
+186
View File
@@ -0,0 +1,186 @@
const NightCityMap = (() => {
const Z = 4, SCALE = 256 * 16;
const B = { x0: 0, y0: 0, x1: 14 * 256, y1: 13 * 256 };
const fracToLatLng = (fx, fy) => {
const px = B.x0 + fx * (B.x1 - B.x0);
const py = B.y0 + fy * (B.y1 - B.y0);
return L.latLng(pyToLat(py), pxToLng(px));
};
const pxToLng = (px) => (px / SCALE) * 360 - 180;
const pyToLat = (py) => {
const n = Math.PI * (1 - (2 * py) / SCALE);
return (Math.atan(Math.sinh(n)) * 180) / Math.PI;
};
const latLngToUnits = (latlng) => {
const p = L.CRS.EPSG3857.latLngToPoint(L.latLng(latlng), Z);
const u = ((p.x - B.x0) / (B.x1 - B.x0)) * 1000;
const v = ((p.y - B.y0) / (B.y1 - B.y0)) * 700;
return {
x: Math.max(0, Math.min(1000, u)),
y: Math.max(0, Math.min(700, v)),
};
};
const DISTRICTS = [
{ name: 'Watson', box: [0.03, 0.03, 0.30, 0.24] },
{ name: 'City Center', box: [0.33, 0.02, 0.54, 0.18] },
{ name: 'Westbrook', box: [0.55, 0.04, 0.90, 0.28] },
{ name: 'Heywood', box: [0.22, 0.26, 0.66, 0.60] },
{ name: 'Santo Domingo', box: [0.66, 0.28, 0.95, 0.62] },
{ name: 'Pacifica', box: [0.06, 0.62, 0.42, 0.95] },
{ name: 'Badlands', box: [0.42, 0.62, 1.00, 0.97] },
{ name: 'Badlands', box: [0.90, 0.10, 1.00, 0.60] },
];
const POIS = [
{ id: 'kabuki', name: 'Kabuki Market', fx: 0.13, fy: 0.10 },
{ id: 'arasaka', name: 'Arasaka Waterfront', fx: 0.50, fy: 0.045 },
{ id: 'corpo', name: 'Corpo Plaza', fx: 0.44, fy: 0.10 },
{ id: 'japantown', name: 'Japantown', fx: 0.63, fy: 0.15 },
{ id: 'afterlife', name: 'Afterlife', fx: 0.42, fy: 0.30 },
{ id: 'mbh10', name: 'Megabuilding H10', fx: 0.33, fy: 0.42 },
{ id: 'dogtown', name: 'Dogtown Gate', fx: 0.55, fy: 0.70 },
{ id: 'mall', name: 'Grand Illusion Mall', fx: 0.23, fy: 0.78 },
].map((p) => ({ ...p, latlng: fracToLatLng(p.fx, p.fy), units: { x: p.fx * 1000, y: p.fy * 700 } }));
let map;
const points = { A: null, B: null };
let onChange = () => {};
let routeLine = null;
const markers = { A: null, B: null };
function districtAt(units) {
const fx = units.x / 1000, fy = units.y / 700;
for (const d of DISTRICTS) {
const [x0, y0, x1, y1] = d.box;
if (fx >= x0 && fx <= x1 && fy >= y0 && fy <= y1) return d.name;
}
return 'Night City outskirts';
}
function nearestPOI(units) {
let best = null, bestD = 55;
for (const p of POIS) {
const d = Math.hypot(p.units.x - units.x, (p.units.y - units.y) * (10 / 7));
if (d < bestD) { bestD = d; best = p; }
}
return best;
}
function placeName(units) {
const poi = nearestPOI(units);
return poi ? poi.name : districtAt(units);
}
function pinIcon(color, label) {
return L.divIcon({
className: 'nc-pin-wrap',
html: `<div class="nc-pin" style="--pin:${color}"></div><div class="nc-pin-label" style="--pin:${color}">${label}</div>`,
iconSize: [0, 0],
iconAnchor: [0, 0],
});
}
function render() {
for (const key of ['A', 'B']) {
const p = points[key];
if (markers[key]) { markers[key].remove(); markers[key] = null; }
if (p) {
markers[key] = L.marker(p.latlng, {
icon: pinIcon(key === 'A' ? '#00d4ff' : '#ffe600', key),
zIndexOffset: 1000,
keyboard: false,
}).addTo(map);
}
}
if (routeLine) { routeLine.remove(); routeLine = null; }
if (points.A && points.B) {
const { A, B } = points;
const mid = fracToLatLng(
(A.fx + B.fx) / 2 + (B.fy - A.fy) * 0.08,
(A.fy + B.fy) / 2 - (B.fx - A.fx) * 0.08
);
routeLine = L.polyline([A.latlng, mid, B.latlng], {
color: '#00f0ff',
weight: 4,
opacity: 0.9,
dashArray: '12 10',
className: 'nc-route',
}).addTo(map);
map.fitBounds(L.latLngBounds(A.latlng, B.latlng).pad(0.25), { animate: true });
}
}
function setPoint(which, latlng) {
if (which === 'A' && points.A && points.B) {
points.A = null; points.B = null;
which = 'A';
}
const units = latLngToUnits(latlng);
points[which] = {
latlng: L.latLng(latlng),
lat: latlng.lat, lng: latlng.lng,
x: units.x, y: units.y,
fx: units.x / 1000, fy: units.y / 700,
name: placeName(units),
};
render();
onChange({ A: points.A, B: points.B });
}
function init(container, callback) {
map = L.map(container, {
minZoom: 3,
maxZoom: 5,
zoomControl: true,
attributionControl: false,
maxBounds: L.latLngBounds(fracToLatLng(-0.03, -0.03), fracToLatLng(1.03, 1.03)),
maxBoundsViscosity: 0.7,
});
map.setView(fracToLatLng(0.5, 0.45), 4);
L.tileLayer('img/tiles/{z}/{x}/{y}.webp', {
minZoom: 3,
maxZoom: 5,
noWrap: true,
bounds: L.latLngBounds(fracToLatLng(0, 0), fracToLatLng(1, 1)),
}).addTo(map);
for (const p of POIS) {
L.marker(p.latlng, {
icon: L.divIcon({
className: 'nc-poi-wrap',
html: `<div class="nc-poi"></div><div class="nc-poi-label">${p.name}</div>`,
iconSize: [0, 0],
}),
keyboard: false,
})
.on('click', (e) => {
L.DomEvent.stopPropagation(e);
setPoint(points.A === null ? 'A' : 'B', p.latlng);
})
.addTo(map);
}
map.on('click', (e) => setPoint(points.A === null ? 'A' : 'B', e.latlng));
if (callback) onChange = callback;
}
return {
init,
setPoint: (which, latlng) => setPoint(which, latlng),
get points() { return points; },
reset() {
points.A = null; points.B = null;
render();
map.setView(fracToLatLng(0.5, 0.45), 4);
onChange({ A: null, B: null });
},
refresh() {
if (map) map.invalidateSize({ animate: false });
},
};
})();
+54
View File
@@ -0,0 +1,54 @@
const utils = {
showModal: (id) => { document.getElementById(id).style.display = 'flex'; },
hideModal: (id) => { document.getElementById(id).style.display = 'none'; },
notify: (message, type = 'info') => {
const n = document.createElement('div');
n.className = `notification ${type}`;
n.textContent = message;
document.body.appendChild(n);
setTimeout(() => n.remove(), 3500);
},
showError: (error) => {
console.error(error);
utils.notify(error.message || String(error), 'error');
},
formatDate: (s) => {
if (!s) return '';
const d = new Date(s);
return isNaN(d) ? s : d.toLocaleString();
},
empty: (id, msg) => {
document.getElementById(id).innerHTML = `<div class="empty">${msg}</div>`;
},
escapeHtml: (s) => {
const div = document.createElement('div');
div.textContent = s == null ? '' : String(s);
return div.innerHTML;
},
tripCard: (trip) => {
const card = document.createElement('div');
card.className = 'trip-card';
card.innerHTML = `
<div class="trip-header">
<h3>${utils.escapeHtml(trip.id)}</h3>
<span class="trip-class">${utils.escapeHtml(trip.class || '')}</span>
</div>
<div class="trip-details">
<div class="trip-detail"><span class="label">Status</span><span>${utils.escapeHtml(trip.status || '')}</span></div>
<div class="trip-detail"><span class="label">Created</span><span>${utils.escapeHtml(utils.formatDate(trip.created_at))}</span></div>
</div>
<div class="trip-actions">
<button class="btn btn-small btn-outline" data-act="view" data-id="${utils.escapeHtml(trip.id)}">View</button>
<button class="btn btn-small btn-outline" data-act="versions" data-id="${utils.escapeHtml(trip.id)}">Versions</button>
<button class="btn btn-small btn-outline" data-act="export" data-id="${utils.escapeHtml(trip.id)}">Export</button>
</div>`;
return card;
},
};