diff --git a/Docs/Maps_Stage1.md b/Docs/Maps_Stage1.md index f9732e00..23d1a404 100644 --- a/Docs/Maps_Stage1.md +++ b/Docs/Maps_Stage1.md @@ -1,6 +1,6 @@ # Maps Stage 1 -Maps is a project-scoped spatial writing workspace. Open **World → Maps**, choose a map, or create one. The project selector supplies `projectId` to `/Maps`; selected maps add `id`. +Maps is a project-scoped spatial writing workspace. The direct `/Maps` address offers your active projects; it never selects another author’s project. Open **World → Maps**, choose a map, or create one. The project selector supplies `projectId` to `/Maps`; selected maps add `id`. ## Author workflows diff --git a/PlotLine.Tests/Browser/maps-dev-smoke.cjs b/PlotLine.Tests/Browser/maps-dev-smoke.cjs index 646ff523..9866ac67 100644 --- a/PlotLine.Tests/Browser/maps-dev-smoke.cjs +++ b/PlotLine.Tests/Browser/maps-dev-smoke.cjs @@ -16,6 +16,7 @@ const base='https://dev.plotdirector.com'; await Promise.all([page.waitForURL('**/Projects'),page.locator('form[action="/Account/Login"] button[type=submit]').click()]); await page.goto(base+'/Projects/Create');await page.locator('#ProjectName').fill('Maps Development smoke '+Date.now());await page.getByRole('button',{name:'Save project',exact:true}).click(); await page.waitForURL(/\/Projects(?:\/Details)?\//);const projectId=Number(page.url().match(/\/(\d+)(?:\?|$)/)[1]); + await page.goto(base+'/Maps');assert(await page.locator(`a[href="/Maps?projectId=${projectId}"]`).isVisible(),'direct Maps launcher lists the signed-in author’s project'); await page.goto(base+'/Maps?projectId='+projectId);await page.locator('#mapsNew').click(); await page.locator('#mapsNewForm [name=Name]').fill('Working world');await page.locator('#mapsNewForm [name=Kind]').selectOption('World');await page.locator('#mapsNewForm [name=Starter]').selectOption('island'); await Promise.all([page.waitForURL(/&id=\d+/),page.locator('#mapsNewForm button[type=submit]').click()]); @@ -34,8 +35,9 @@ const base='https://dev.plotdirector.com'; const locationID=await page.evaluate(id=>window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id).locationID,towns[0].featureID);assert(locationID>0); await page.reload();await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);assert.equal(await page.locator('.maps-feature').count(),7); assert(await page.evaluate(({id,locationID})=>{const d=window.PlotDirectorMapWorkspace.document;return d.features.find(f=>f.featureID===id).locationID===locationID&&d.relationships[0].measuredDistance===126&&d.relationships[0].typicalTravelTime==='Two hours by car';},{id:towns[0].featureID,locationID})); - // A second save must keep the same canonical Location ID. - await page.locator('#mapsSave').click();await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved'); + // Save from a focused name field must commit the edit and reuse the same canonical Location ID. + await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),towns[0].featureID);await page.locator('[data-field=name]').fill('Harbour town revised');await page.keyboard.press('Control+s');await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved'); + assert(await page.evaluate(({id,locationID})=>{const f=window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id);return f.name==='Harbour town revised'&&f.locationID===locationID;},{id:towns[0].featureID,locationID})); await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),towns[0].featureID);await page.locator('[data-action=child]').click();await page.locator('#mapsNewForm [name=Name]').fill('Harbour detail'); const rootID=new URL(rootURL).searchParams.get('id');await page.locator('#mapsNewForm button[type=submit]').click();await page.waitForURL(url=>url.searchParams.get('id')!==rootID&&url.pathname==='/Maps');await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace); assert.equal(await page.locator('#mapsBreadcrumbs a').count(),3,'hierarchy breadcrumbs');const childURL=page.url(); diff --git a/PlotLine/Controllers/MapsController.cs b/PlotLine/Controllers/MapsController.cs index 47699460..e9f30bee 100644 --- a/PlotLine/Controllers/MapsController.cs +++ b/PlotLine/Controllers/MapsController.cs @@ -13,6 +13,7 @@ public sealed class MapsController(MapRepository maps, IProjectRepository projec private int UserID => currentUser.UserId!.Value; public async Task Index(int projectId, int? id) { + if (projectId == 0) return View("ChooseProject", await projects.ListActiveForUserAsync(UserID)); if (!await access.CanAccessProjectAsync(projectId)) return NotFound(); var project = await projects.GetForUserAsync(projectId, UserID); if (project is null) return NotFound(); diff --git a/PlotLine/Views/Maps/ChooseProject.cshtml b/PlotLine/Views/Maps/ChooseProject.cshtml new file mode 100644 index 00000000..4bf8d25c --- /dev/null +++ b/PlotLine/Views/Maps/ChooseProject.cshtml @@ -0,0 +1,22 @@ +@model IReadOnlyList +@{ + ViewData["Title"] = "Maps"; + ViewData["ProjectSection"] = "Maps"; +} +
+

Story geography

Maps

Choose the project whose world you want to explore.

+
+@if (Model.Count == 0) +{ +

Create a project to start arranging your story world.

+ Create project +} +else +{ +
+ @foreach (var project in Model) + { + @project.ProjectName + } +
+} diff --git a/PlotLine/wwwroot/js/maps-workspace.js b/PlotLine/wwwroot/js/maps-workspace.js index f40a454e..fe7345dc 100644 --- a/PlotLine/wwwroot/js/maps-workspace.js +++ b/PlotLine/wwwroot/js/maps-workspace.js @@ -43,7 +43,7 @@ function world(event){const p=new DOMPoint(event.clientX,event.clientY).matrixTransform(svg.getScreenCTM().inverse());return [p.x,p.y];} function fit(items=doc?.features||[]){if(!items.length){view={x:-600,y:-400,w:1200,h:800};applyView();return;} let left=Infinity,top=Infinity,right=-Infinity,bottom=-Infinity; - for(const f of items){let pts=f.geometryClass==='Path'?E.pathPoints(f,doc.features):[[f.x-f.width/2,f.y-f.height/2],[f.x+f.width/2,f.y+f.height/2]];for(const p of pts){left=Math.min(left,p[0]);right=Math.max(right,p[0]);top=Math.min(top,p[1]);bottom=Math.max(bottom,p[1]);}} + for(const f of items){let pts=f.geometryClass==='Path'?E.pathPoints(f,doc.features):f.geometryClass==='Area'?(E.geometry(f).points||[[-.5,-.5],[.5,.5]]).map(p=>E.localToWorld(f,p)):[[f.x-f.width/2,f.y-f.height/2],[f.x+f.width/2,f.y+f.height/2]];for(const p of pts){left=Math.min(left,p[0]);right=Math.max(right,p[0]);top=Math.min(top,p[1]);bottom=Math.max(bottom,p[1]);}} let w=Math.max(350,right-left+180),h=Math.max(250,bottom-top+180),ratio=svg.clientWidth/Math.max(1,svg.clientHeight);if(w/h1){content.innerHTML=search+`

${selected.size} pieces selected.

`;return;} const child=boot.maps.find(m=>m.parentMapID===doc.map.mapID&&m.parentFeatureID===f.featureID),linked=boot.locations.find(l=>l.locationID===f.locationID); const readonly=mode!=='create'; - let html=search+`

${esc(f.name)}

${esc(f.type)}${f.isProvisional?' · ◇ Planning':''}${f.isLocked?' · Locked':''}

`; + let html=search+`

${esc(f.name)}

${esc(f.type)}${f.isProvisional?' · ◇ Planning':''}${f.isLocked?' · Locked':''}${!f.isPlaced?' · Unplaced':''}

`; if(readonly){html+=f.notes?`

${esc(f.notes)}

`:'';if(linked)html+=`Open story Location: ${esc(linked.locationName)}`;} else{ html+=`
${field('Name','name',f.name,'text','id="mapName" maxlength="200"')}`; @@ -203,10 +203,10 @@ svg.addEventListener('wheel',e=>{e.preventDefault();zoom(e.deltaY>0?1.12:1/1.12,world(e));},{passive:false}); svg.addEventListener('contextmenu',e=>{e.preventDefault();const id=e.target.closest('[data-feature-id]')?.dataset.featureId;if(!id||mode!=='create')return;select(id);contextMenu?.remove();contextMenu=document.createElement('div');contextMenu.className='maps-context-menu';contextMenu.style.left=Math.min(e.clientX,window.innerWidth-180)+'px';contextMenu.style.top=Math.min(e.clientY,window.innerHeight-170)+'px';contextMenu.innerHTML='';app.append(contextMenu);}); document.addEventListener('keydown',e=>{ + if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='s'&&!e.target.closest('dialog')){e.preventDefault();if(e.target.matches('[data-field]'))e.target.dispatchEvent(new Event('change',{bubbles:true}));save();return;} if(e.target.matches('input,textarea,select')||e.target.isContentEditable)return; if(e.key==='Escape'){if(drag&&drag.kind!=='pan'){doc=JSON.parse(history.pop());drag=null;}pending=null;selected.clear();shapeEdit=false;contextMenu?.remove();svg.classList.remove('placing');render();details();return;} if(e.target.closest('dialog'))return; - if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='s'){e.preventDefault();save();return;} if(mode!=='create'||busy||preview)return; if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='z'){e.preventDefault();undo(e.shiftKey);} if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='y'){e.preventDefault();undo(true);}