Skip to content

Commit

Permalink
Make the Nexus ***dynamic***.
Browse files Browse the repository at this point in the history
This removes the Nexus's reliance on linking panel objects in the
PRP/max file for each Age. Instead, we now replace the texture on the
single linking book in game with the correct one. The correct linking
panel is searched for by name in the PRPs, so it is dependent on either
the Nexus's textures PRP or the GUI PRPs to have the appropriate linking
panels.
  • Loading branch information
Hoikas committed Nov 19, 2024
1 parent 83c6af8 commit 579882c
Showing 1 changed file with 75 additions and 36 deletions.
111 changes: 75 additions & 36 deletions Scripts/Python/nxusBookMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@
Mead, WA 99021
*==LICENSE==* """
"""
Module: nxusBookMachine
Age: nexus
Date: September, 2002
Author: Bill Slease
Handler for the nexus book machine.
"""

from __future__ import annotations

from Plasma import *
from PlasmaKITypes import *
Expand All @@ -58,8 +53,11 @@
import xLocTools

import PlasmaControlKeys

import datetime
import random
import re
from typing import *

# define the attributes that will be entered in max
NexusGUI = ptAttribGUIDialog(1, "The Nexus GUI")
Expand All @@ -78,8 +76,9 @@
actGetBook = ptAttribActivator(14, "Actvtr: Get Book")
respGetBook = ptAttribResponder(15, "Rspndr: Get Book")
respButtonPress = ptAttribResponder(16, "Rspndr: GetBook Btn Press") # onInit
objlistLinkPanels = ptAttribSceneobjectList(17, "Objct: Link Panels")
objlistLinkPanels = ptAttribSceneobjectList(17, "Objct: Link Panels") # Dead
respKISlotGlow = ptAttribResponder(18, "Rspndr: KI Slot Glow")
layLinkPanel = ptAttribLayer(19, "Layer: Linking Panel")

#------nexus machine GUI tags
kNexusDialogName = "NexusAgeDialog"
Expand Down Expand Up @@ -180,28 +179,19 @@
kNumDisplayFields = 8
kMaxDisplayableChars = 24 # the avg number of chars to display before tacking on an ellipsis: "..."

#special named link panels (other then 'LinkPanel_' + Age Filename)
kLinkPanels = {
'city' : {'LinkInPointFerry' : 'LinkPanel_Ferry Terminal',
'LinkInPointDakotahAlley' : 'LinkPanel_Dakotah Alley',
'LinkInPointPalace' : 'LinkPanel_Palace Alcove',
'LinkInPointConcertHallFoyer' : 'LinkPanel_Concert Hall Foyer',
'LinkInPointLibrary' : 'LinkPanel_Library Courtyard'
},
'Cleft' : {
#That would be conspicious, if Nexus allowed to link to rainy cleft, unless we belive in great Nexus-Maintainers-Bahro conspiracy
'SpawnPointTomahna01' : 'LinkPanel_Tomahna',
#Umm, why Nexus even has entry for some boring hole in ground on surface?
'' : 'LinkPanel_Cleft',
},

'GreatZero' : {'' : 'LinkPanel_Great Zero Observation',
'BigRoomLinkInPoint' : 'LinkPanel_GreatZero'
},
'Neighborhood02' : {'' : 'LinkPanel_Kirel'
},
# Specially named link panel textures
kLinkPanels: Dict[Tuple[str, str], str] = {
("Ahnonay", "Default"): "xlinkpanelahnonayvortex",
("GreatZero", "Great Zero"): "xlinkpanelgrtzero",
}

# Special replacements used in some filenames
kLinkPanelInstances: Dict[str, str] = {
"AhnonayCathedral": "ahnonaytemple",
"EderTsogal": "tsogarden",
"GreatZero": "grtzero",
"Neighborhood": "Bevin",
}

kHiddenPersonalAges = ["Personal", "Nexus", "Neighborhood", "city", "AvatarCustomization", "Cleft", "BaronCityOffice", "BahroCave", "PelletBahroCave", "Kveer", "Myst", "LiveBahroCaves", "LiveBahroCave", "ChisoPreniv", "GoMePubNew", "FahetsHighgarden"]
kHiddenCityLinks = ["islmPalaceBalcony03", "KadishGallery", "islmPalaceBalcony02", "islmDakotahRoof", "islmGreatTree"]
Expand Down Expand Up @@ -363,6 +353,8 @@ def __init__(self):
PtLanguage.kGerman : True
}

self.defaultPanelImage = None

def OnFirstUpdate(self):
"First update, load GUI dialog, give player PAL to Nexus"
PtLoadDialog(kNexusDialogName, self.key, "Nexus")
Expand All @@ -372,10 +364,13 @@ def OnFirstUpdate(self):
respBookRetract.run(self.key, fastforward = 1)
respButtonPress.run(self.key, fastforward = 1)

# hide all the linking panels in the machine - will draw appropriate when selected
# hide all the linking panels in the machine - they are no longer used
for objPanel in objlistLinkPanels.value:
objPanel.draw.disable()

if layLinkPanel.value is not None:
self.defaultPanelImage = layLinkPanel.value.getTexture()

def OnServerInitComplete(self):
ageSDL = PtGetAgeSDL()
for (ageName, (maxPopVar, linkVisibleVar)) in kAgeSdlVariables.items():
Expand Down Expand Up @@ -1217,17 +1212,61 @@ def IDeleteLink(self):
self.IUpdateLinks()
return

def IGeneratePotentialLinkPanels(self, als: ptAgeLinkStruct) -> Generator[Iterable[ptImage]]:
def gen(name: str) -> Iterable[ptImage]:
# Texture names (should) be all lowercase.
name = re.sub(r"[ '\"]", "", name.lower())
PtDebugPrint(f"nxusBookMachine.IGeneratePotentialLinkPanels: Generating images for {name=}", level=kWarningLevel)
return PtFindImage(name)

info = als.getAgeInfo()
filename = info.getAgeFilename()
swpt = als.getSpawnPoint()
swptTitle = swpt.getTitle()

if hardcodedName := kLinkPanels.get((filename, swptTitle)):
PtDebugPrint(f"IGeneratePotentialLinkPanels: Generated images for hardcoded name {hardcodedName}", level=kWarningLevel)
yield PtFindImage(hardcodedName)
return

def gen_by_swpt(name: str, title: str) -> Generator[Iterable[ptImage]]:
yield gen(f"xlinkpanel{name}{title}")
if title == "Default":
yield gen(f"xlinkpanel{name}")

if ageName := kLinkPanelInstances.get(filename):
yield from gen_by_swpt(ageName, swptTitle)

yield from gen_by_swpt(filename, swptTitle)
if swptTitle.lower() != "default":
yield gen(f"xlinkpanel{swptTitle}")
yield from gen_by_swpt(info.getAgeInstanceName(), swptTitle)

def IDrawLinkPanel(self):
if self.presentedBookAls is None:
PtDebugPrint("nxusBookMachine.IDrawLinkPanel: trying to draw panel without selected book!")
return
if layLinkPanel.value is None:
PtDebugPrint("nxusBookMachine.IDrawLinkPanel: trying to draw panel with old PRPs!")
return

# Generate a series of potential link panel image names and search for them,
# selecting the first matching panel name.
panelGen = self.IGeneratePotentialLinkPanels(self.presentedBookAls)
if panelImages := next(filter(None, panelGen), None):
# Some Ages will have multiple panels that match our lazy string lookup,
# and, in some cases, the first match is a very low resolution postage stamp.
# These are probably coming from the in-world texture on the book. So,
# sort the list so we can get the biggest and therefore clearest one.
panelImages = sorted(
panelImages,
key=lambda x: x.getWidth() * x.getHeight()
)
PtDebugPrint("nxusBookMachine.IDrawLinkPanel: Drawing link panel!", level=kWarningLevel)
layLinkPanel.value.setTexture(panelImages[-1])
else:
panelName = self.IGetLinkPanelName(self.presentedBookAls)
PtDebugPrint("drawing link panel: %s" % (panelName))
for objPanel in objlistLinkPanels.value:
if objPanel.getName() == panelName:
objPanel.draw.enable()
else:
objPanel.draw.disable()
PtDebugPrint("nxusBookMachine.IDrawLinkPanel: Drawing default panel for unknown Age")
layLinkPanel.value.setTexture(self.defaultPanelImage)

def IChoosePublicInstances(self):
for (ageFilename, entry) in self.publicAges.items():
Expand Down

0 comments on commit 579882c

Please sign in to comment.