from pathlib import Path import re, math, json, html from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, Paragraph, Spacer, PageBreak, Table, TableStyle, KeepTogether, Flowable, Image as RLImage from reportlab.platypus.tableofcontents import TableOfContents from reportlab.lib import colors from reportlab.lib.styles import ParagraphStyle from reportlab.lib.enums import TA_LEFT from reportlab.lib.pagesizes import A4 from reportlab.lib.utils import ImageReader from PIL import Image as PILImage from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont from pypdf import PdfReader import yaml ROOT = Path(__file__).resolve().parents[2] OUT = ROOT / 'docs/Dune-Complete-Illustrated-Manual.pdf' OUT.parent.mkdir(parents=True, exist_ok=True) def pdf_art_file(path): path=Path(path) im=PILImage.open(path) if max(im.size)<1000:return str(path) import hashlib cache=ROOT/'tmp/pdfs/print-art';cache.mkdir(parents=True,exist_ok=True) target=cache/(path.stem+'-'+hashlib.sha1(str(path).encode()).hexdigest()[:8]+'.jpg') if not target.exists() or target.stat().st_mtime\1',s) s=re.sub(r'`(.*?)`',r'\1',s) return s class Manual(BaseDocTemplate): def __init__(self,*args,**kwargs): super().__init__(*args,**kwargs) self.chapter='FIELD MANUAL' def afterFlowable(self, f): if getattr(f,'toc_title',None): key='chapter-'+str(self.page)+'-'+str(abs(hash(f.toc_title))) self.canv.bookmarkPage(key) self.canv.addOutlineEntry(f.toc_title,key,0) self.notify('TOCEntry',(0,f.toc_title,self.page,key)) self.chapter=f.toc_title.upper() def footer(c,doc): if doc.page==1: art=ImageReader(pdf_art_file(ART/'arrakis-cover.png'));iw,ih=art.getSize();scale=max(W/iw,H/ih) c.drawImage(art,(W-iw*scale)/2,(H-ih*scale)/2,width=iw*scale,height=ih*scale) c.setFillColor(colors.HexColor('#162424'));c.setFillAlpha(.62);c.rect(0,H-290,W,290,fill=1,stroke=0);c.setFillAlpha(1) c.setFillColor(PALE);c.setFont('ArialBold',10);c.drawString(48,H-56,'PROJECT DUNE / PLAYER + ADMIN EDITION') c.setFont('GeorgiaBold',68);c.drawString(48,H-140,'DUNE') c.setFont('Arial',25);c.drawString(48,H-178,'The illustrated field manual') c.setFont('Arial',11);c.drawString(48,H-213,'ARRAKIS / FACTIONS / SPICE / THE VAERKRING') c.setStrokeColor(PALE);c.line(48,H-233,W-48,H-233) c.setFont('Arial',9);c.drawString(48,H-251,'DuneCore 1.0.8 | DuneNPC 1.0.0 | DuneTerrain 1.0.7 | DuneEss 1.0.1') c.setFillColor(colors.HexColor('#102322'));c.setFillAlpha(.80);c.rect(0,0,W,59,fill=1,stroke=0);c.setFillAlpha(1) c.setFillColor(PALE);c.setFont('Arial',9);c.drawString(48,34,'Minecraft Java / Paper 1.21.4 / Java 21');c.drawString(48,19,'NPC edition / 13 October 2026 / 68 illustrated reference icons') return c.setFillColor(colors.HexColor('#fcf9f1'));c.rect(0,0,W,H,fill=1,stroke=0) c.setStrokeColor(colors.HexColor('#e7dac0'));c.setLineWidth(.6) for offset in range(3): p=c.beginPath();p.moveTo(0,8+offset*5) for x in range(0,int(W)+20,15):p.lineTo(x,8+offset*5+4*math.sin(x/90+offset*.6)) c.drawPath(p,stroke=1,fill=0) c.setStrokeColor(PALE);c.setLineWidth(1);c.line(48,H-45,W-48,H-45) c.setFont('ArialBold',8);c.setFillColor(GOLD);c.drawString(48,H-35,'DUNE / USER MANUAL') c.setFont('Arial',8);c.drawRightString(W-48,H-35,'NPC EDITION / 13 OCTOBER 2026') c.setStrokeColor(PALE);c.line(48,44,W-48,44) c.setFillColor(INK);c.setFont('Arial',8);c.drawString(48,30,'PLAYER + ADMIN EDITION') c.drawRightString(W-48,30,str(doc.page)) def artwork_intro(title, subtitle, image): story.extend([Paragraph('ILLUSTRATED FIELD NOTES',STYLE['label'])]) heading=Paragraph(title,STYLE['title']);heading.toc_title=title;story.append(heading) story.append(Image(str(image),width=W-96,height=(W-96)*PILImage.open(image).height/PILImage.open(image).width)) story.extend([Spacer(1,15),Paragraph(subtitle,STYLE['body']),Spacer(1,20),Paragraph('THE SPICE MUST FLOW',STYLE['title']), table(['|Shelter|Spice|Shai-Hulud|','|A complete stillsuit and a reliable sietch are the start of every expedition.|Recognize the tagged shovel and harvestable deposits before taking a quota job.|Watch sightings, prepare for combat, and treat coordinates as an initial report.|']),Spacer(1,12), Paragraph('Concept artwork illustrates the theme; it is not a screenshot or a promise of additional game structures.',STYLE['small']),PageBreak()]) class GuildTimeline(Flowable): def __init__(self):super().__init__();self.width=W-96;self.height=86 def draw(self): c=self.canv;c.setStrokeColor(GOLD);c.setFillColor(GOLD);c.setLineWidth(1.4) xs=[26,self.width/2,self.width-26] c.line(xs[0],55,xs[-1],55) for x in xs:c.circle(x,55,4,fill=1,stroke=0) c.setFont('ArialBold',9);c.setFillColor(INK) c.drawString(0,70,'ARRAKIS SIGHTING');c.drawCentredString(xs[1],70,'15 REAL MINUTES');c.drawRightString(self.width,70,'GUILD NOTICE') c.setFont('Arial',8) c.drawString(0,34,'Coordinates + local warning');c.drawCentredString(xs[1],34,'Deadline survives restart');c.drawRightString(self.width,34,'All online proxy players') c.setFillColor(GOLD);c.drawCentredString(self.width/2,13,'If Arrakis is empty at the deadline, delivery waits for a player connection.') def table(lines, widths=None): rows=[[x.strip() for x in line.strip('|').split('|')] for line in lines] cols=len(rows[0]); width=W-96 if widths is None: widths=[width*.43,width*.57] if cols==2 else [width/cols]*cols data=[[Paragraph(markup(cell), STYLE['headcell' if r==0 else 'cell']) for cell in row] for r,row in enumerate(rows)] t=Table(data,colWidths=widths,repeatRows=1,hAlign='LEFT') t.setStyle(TableStyle([('BACKGROUND',(0,0),(-1,0),INK),('ROWBACKGROUNDS',(0,1),(-1,-1),[colors.white,colors.HexColor('#f6f1e8')]), ('VALIGN',(0,0),(-1,-1),'TOP'),('LEFTPADDING',(0,0),(-1,-1),9),('RIGHTPADDING',(0,0),(-1,-1),9), ('TOPPADDING',(0,0),(-1,-1),7),('BOTTOMPADDING',(0,0),(-1,-1),7),('LINEBELOW',(0,0),(-1,0),1,GOLD)])) return t class Notes(Flowable): def __init__(self,height=230):super().__init__();self.width=W-96;self.height=height def draw(self): self.canv.setStrokeColor(PALE);self.canv.setLineWidth(.7) for y in range(20,int(self.height),25):self.canv.line(0,y,self.width,y) def hero_page(title, filename, caption): art = ROOT/'docs/artwork'/filename iw, ih = PILImage.open(art).size height = 510 width = height*iw/ih if width > W-96: width = W-96 height = width*ih/iw heading = Paragraph(title, STYLE['title']); heading.toc_title = title picture = Image(str(art), width=width, height=height); picture.hAlign='CENTER' story.extend([Paragraph('DUNE / ILLUSTRATED WORLDS AND CHARACTERS',STYLE['label']), heading, picture, Spacer(1,14), Paragraph(caption,STYLE['body']), Paragraph('Concept artwork. The adjacent guide describes the implemented plugin behavior.',STYLE['small']), PageBreak()]) HEROES = { 'Meeting the roaming smugglers': ('A contact beyond the ledgers','smuggler-spice-mission.png','Sand-tan robes and green dust identify a roaming contact. Approach on Arrakis and right-click to see the smuggling offers available to your house.'), 'Water for the Hidden Sietch': ('A light in the desert','smuggler-water-camp.png','Purple dust marks an active quest contact. Invisible light blocks brighten its camp while the player carries water toward a different smuggler.'), 'The Imperial Admin Scepter': ('The keeper of the routes','imperial-npc-administration.png','The glowing blaze rod opens operator controls. DuneNPC manages Guild Navigators, smugglers and their missions through its own linked administration page.'), 'The Arrakduin landscape': ('Arrakduin / the desert world','world-0.png','Arrakis receives the full gameplay treatment in this edition: terrain, spice, sietches, survival, worms, rights and smuggling. This is the active field guide.'), 'Giedi Prime': ('Giedi Prime / industrial shadows','world-1.png','A lore-inspired view of the Harkonnen world. The following reserved chapter records the released swamp and blackstone profile; the depicted industry is concept scenery.'), 'Kaitain': ('Kaitain / the Imperial horizon','world-2.png','A lore-inspired Imperial vista. The following reserved chapter records the released plains, flowers and ores; palace architecture is concept scenery.'), 'Caladan': ('Caladan / water and green lands','world-3.png','A lore-inspired Atreides vista. The following reserved chapter records the current jungle and water profile; additional local missions remain future documentation.'), 'Sigma Draconis IV': ('Sigma Draconis IV / cold horizons','world-4.png','An Ordos-inspired cold-world concept. The following reserved chapter documents snowy terrain; new settlements and local survival systems are not implied.') } story=[Spacer(1,10),PageBreak()] toc=TableOfContents();toc.levelStyles=[ParagraphStyle('toc',fontName='Arial',fontSize=9.5,leading=13.5,spaceBefore=1,textColor=INK)] toc.tableStyle=TableStyle([('VALIGN',(0,0),(-1,-1),'TOP'),('LEFTPADDING',(0,0),(-1,-1),0),('RIGHTPADDING',(0,0),(-1,-1),0),('TOPPADDING',(0,0),(-1,-1),1),('BOTTOMPADDING',(0,0),(-1,-1),1)]) story += [Paragraph('HOW TO USE THIS BOOK',STYLE['label']),Paragraph('Contents',STYLE['title']),Paragraph('Player guidance comes first, followed by command references and server administration. Each of the four reserved planet chapters contains its currently implemented profile and space for future additions. Configuration values shown here are shipped defaults; your administrator may change them.',STYLE['body']),toc,PageBreak()] raw=Path(__file__).with_name('manual-current-content.txt').read_text(encoding='utf-8') artwork_intro('Beneath the sands of Arrakduin','A field guide to the desert: reach a sietch, prepare your stillsuit, follow the spice and watch for Shai-Hulud. The gameplay chapters that follow explain exactly what the release implements.',ART/'sietch-panorama.png') for block in raw.split('\n===PAGE===\n'): lines=block.strip().splitlines() if not lines:continue label,title=lines.pop(0).split(' | ',1) if title in HEROES: hero_page(*HEROES[title]) scenes={ 'Harvesting melange': ('Melange among the terraces','spice-expedition.png','Wear your stillsuit, recognize the tagged netherite shovel and harvest the desert. Fremen receive two spice units per deposit. The plateau formations can have up to three levels, with at most five blocks between their heights.'), 'Shai-Hulud: model, AI and combat': ('When Shai-Hulud rises','shai-hulud-encounter.png','A visible Sniffer body carries the sandworm skin while an invisible Husk supplies native zombie AI. Fight the visible body. Its default 500 health makes it a serious encounter; its death creates a rich spice field rather than a direct cash payout.'), 'The five-backend network': ('The Guild connects the worlds','guild-navigator.png','The Vaerkring navigator opens planet travel. Arrakis sighting coordinates remain local for fifteen real minutes before the Guild informs the proxy network. The heighliner in this illustration is lore scenery, not a flyable feature in the plugin.') } if title in scenes: scene_title,filename,caption=scenes[title] sh=Paragraph(scene_title,STYLE['title']);sh.toc_title=scene_title story.extend([Paragraph('ARRAKDUIN / ILLUSTRATED FIELD NOTES',STYLE['label']),sh,Image(str(ROOT/'docs/artwork'/filename),width=W-96,height=(W-96)*2/3),Spacer(1,20),Paragraph(caption,STYLE['body']),Spacer(1,12),Paragraph('The spice must flow.',STYLE['sub']),Paragraph('Concept artwork illustrates the game\'s themes. Creature scale and architecture are artistic interpretations, not screenshots. The following chapter describes the actual release behavior.',STYLE['small']),PageBreak()]) heading=Paragraph(markup(title),STYLE['title']);heading.toc_title=title story += [Paragraph(markup(label.upper()),STYLE['label']),heading] if title=='The fifteen-minute Guild notice':story.append(GuildTimeline()) i=0 while i