Integrate the compact DuneMenus layout #46

Merged
unimatrix merged 2 commits from feat/dunemenus-compact-ui into main 2026-11-30 23:54:00 +01:00
7 changed files with 142 additions and 6 deletions

View file

@ -0,0 +1,44 @@
name: Compact DuneMenus Build
on:
workflow_dispatch:
push:
branches: ['feat/dunemenus-compact-*']
jobs:
compact-menus:
runs-on: dune-ci
steps:
- name: Check out exact revision
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '9.2.1'
- name: Verify the DuneMenus-only transition
shell: bash
run: |
set -euo pipefail
gradle --no-daemon -p DuneMenus test jar
python3 tools/test_plugin_fleet_install.py -v
python3 tools/plugin_compact_menus.py DuneMenus/build/libs/DuneMenus.jar
mkdir compact-menus-artifacts
cp DuneMenus/build/libs/DuneMenus.jar compact-menus-artifacts/
printf '%s\n' "$(git rev-parse HEAD)" > compact-menus-artifacts/SOURCE_COMMIT
python3 tools/write-plugin-manifest.py compact-menus-artifacts "$GITHUB_SHA"
cp tools/{install-plugin-fleet,plugin_compact_menus,plugin_menu_pack,plugin_backend_abi,plugin_fleet_rollback,plugin_pack_properties,plugin_pillager_abi}.py compact-menus-artifacts/
(cd compact-menus-artifacts && sha256sum -- *.jar *.json *.py SOURCE_COMMIT > SHA256SUMS)
- uses: actions/upload-artifact@v3
with:
name: DuneRealms-Compact-Menus
path: compact-menus-artifacts/
if-no-files-found: error

View file

@ -1,7 +1,7 @@
import java.security.MessageDigest
plugins { java }
group = "com.dunerealms"
version = "2.0.8-navigator1"
version = "2.0.9-compact1"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")

File diff suppressed because one or more lines are too long

View file

@ -58,4 +58,29 @@ class SuppliedDocumentTest {
var sell=new Card(49,"Sell item",List.of("List the item in your main hand"),"hopper");var mine=new Card(7,"My listings",List.of("Manage existing listings"),"chest");var item=new Card(13,"Real item",List.of("100 DM"),"iron_sword");
String html=SuppliedDocument.html("exchange","Buy","",List.of(sell,mine,item),List.of());assertTrue(html.contains("class='market-tool' data-slot='49'"));assertTrue(html.contains("class='market-tool' data-slot='7'"));assertTrue(html.contains("class='card n0' data-slot='13'"));assertEquals(1,html.split("data-slot='49'",-1).length-1);
}
@Test void everyFamilyHasOnlyLocalAssetsAndRealActions(){
var allowedSrc=java.util.regex.Pattern.compile("(art/(logo|rihla)\\.png|pack/assets/[a-z0-9_/.-]+\\.png)");
for(String id:List.of("hub","travel","exchange","clan","company","missions","spice","war","politics","house","equipment","bank","atm","withdraw","deposit","redeem","receipt","transfer")){
var cards=new java.util.ArrayList<Card>();var images=new java.util.HashMap<Integer,String>();
for(int n=0;n<6;n++){cards.add(new Card(n,"Entry "+n,List.of("Line "+n),"compass",n!=2));images.put(n,"pack/assets/dunerealms/textures/item/x"+n+".png");}
cards.add(new Card(45,"Back",List.of(),"arrow"));
String html=SuppliedDocument.html(id,id,"sub",cards,List.of("info"),images);
assertFalse(html.matches("(?is).*(href\\s*=|https?:|javascript:|<script|\\son[a-z]+\\s*=|<iframe|<form).*"),id+" has a link or script");
var src=java.util.regex.Pattern.compile("src='([^']*)'").matcher(html);
while(src.find())assertTrue(allowedSrc.matcher(src.group(1)).matches()&&!src.group(1).contains(".."),id+" bad image "+src.group(1));
var slots=new java.util.ArrayList<String>();var m=java.util.regex.Pattern.compile("data-slot='(\\d+)'").matcher(html.replaceAll("(?s)<style>.*?</style>",""));
while(m.find())slots.add(m.group(1));
assertEquals(slots.size(),new java.util.HashSet<>(slots).size(),id+" duplicate action slot");
assertFalse(slots.contains("2"),id+" locked card has an action");
for(String slot:slots){int value=Integer.parseInt(slot);int real=value>=1000?value-1000:value;assertTrue(cards.stream().anyMatch(c->c.slot()==real&&c.enabled()),id+" unknown or locked slot "+slot);}
}
}
@Test void bundledArtFilesExist(){
for(String f:List.of("menu-art/art/logo.png","menu-art/art/rihla.png"))assertNotNull(getClass().getClassLoader().getResource(f),f);
}
@Test void menuIsCentredAtThreeQuartersOfTheCanvas(){
String html=SuppliedDocument.html("hub","Hub","",List.of(),List.of());
assertTrue(html.contains(".frame{width:75%;margin:0 auto"));assertTrue(html.contains("THE SPICE MUST FLOW"));
}
}

View file

@ -75,8 +75,9 @@ def verify_dunechest_fleet_target(sid, root, unit, incoming, installed):
def plan(artifacts, inventory, expected_source):
mode=inventory.get('mode')
if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa'}:
if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus'}:
raise ValueError('An explicit supported rollout mode is required')
compact_menus=mode=='compact-menus'
jerboa=mode=='arrakis-jerboa'
raw_spice=mode=='arrakis-raw-spice'
pillager=mode=='pillager-preserve-economy'
@ -91,6 +92,10 @@ def plan(artifacts, inventory, expected_source):
allowed_names = {'DuneEss', 'DuneRealms', 'DuneCore', 'DuneLobby', 'DuneNPC', 'DunerealmsGUI', 'DuneTerrain', 'JarvisTranslator', 'DuneMenus'}
if dunechest:
allowed_names={'DuneChest'}
if compact_menus:
allowed_names={'DuneMenus'}
if inventory.get('menuPack') is not None:
raise ValueError('Compact menus require retaining the current resource pack')
if jerboa:
allowed_names={'DuneTerrain'}
if raw_spice:
@ -160,11 +165,16 @@ def plan(artifacts, inventory, expected_source):
raise ValueError('Server private prerequisites must be explicitly provided and reviewed')
chosen = [files[name] for name in selected] + [prerequisites[key] for key in selected_prerequisites]
wanted = {entry['name'].casefold() for entry in chosen}
uses_menu='dunemenus' in wanted or bool(menu and menu.get('unified') and not (crysknife or dunechest or jerboa))
uses_menu=not compact_menus and ('dunemenus' in wanted or bool(menu and menu.get('unified') and not (crysknife or dunechest or jerboa)))
if menu and menu.get('unified') and not (crysknife or dunechest or jerboa) and 'dunerealmsgui' not in wanted:
raise ValueError('Unified pack rollout must select its matching DunerealmsGUI adapter')
if not (pillager or crysknife or navigator or dunechest or raw_spice or jerboa) and wanted - {'dunemenus','dunerealmsgui','dunenpc','dunelobby','mcgui'}:
raise ValueError('GUI rollout must retain working Ess/JARVIS/Core/Terrain binaries')
if compact_menus:
expected_root = Path('/opt/dunerealms/lobby') if sid == 'lobby' else Path('/opt/dunerealms/servers') / sid
if (sid not in DUNECHEST_PLANETS | {'lobby'} or root != expected_root or unit != f'dune-{sid}.service'
or wanted != {'dunemenus'} or selected_prerequisites):
raise ValueError('Compact menus may only replace DuneMenus on a reviewed server')
if jerboa and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service'
or wanted != {'duneterrain'} or selected_prerequisites):
raise ValueError('Jerboa rollout may only replace Terrain on Arrakis')
@ -325,6 +335,17 @@ def plan(artifacts, inventory, expected_source):
replaced={entry['filename'] for entry in previous}
retained=[{'filename':path.name,'sha256':digest(path),'metadata':metadata(path)}
for path in sorted(plugins.glob('*.jar')) if path.name not in replaced]
if compact_menus:
from plugin_compact_menus import BASELINE_SHA256, verify_jar
installed = existing_paths.get('dunemenus')
if installed is None or digest(installed) not in {BASELINE_SHA256, chosen[0]['sha256']}:
raise ValueError('Compact menus require the reviewed installed DuneMenus')
if not {'dunerealmsgui', 'jarvistranslator', 'mcgui'}.issubset(existing_paths):
raise ValueError('Compact menus require the retained GUI, JARVIS and MCGUI runtimes')
verify_jar(chosen[0]['source'])
replaced = {entry['filename'] for entry in previous}
retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)}
for path in sorted(plugins.glob('*.jar')) if path.name not in replaced]
if jerboa:
from plugin_arrakis_jerboa import BASELINE_SHA256, verify_terrain
installed = existing_paths.get('duneterrain')

View file

@ -10,7 +10,7 @@
},
"modules": {
"DuneMenus": {
"version": "2.0.8-navigator1",
"version": "2.0.9-compact1",
"changedClasses": [
"com/dunerealms/menus/CanvasProvider.class",
"com/dunerealms/menus/Card.class",

View file

@ -0,0 +1,30 @@
from pathlib import Path
import hashlib
import zipfile
BASELINE_SHA256 = '1b8bbfe5ff34341e54267bca2fb87aabc780e483b5ea015870dd517b99af8871'
OVERLAY = 'com/dunerealms/menus/SuppliedDocument.class'
RETAINED_TREE = 'b8ed957242f45c034250cb482a23f91af7affe11167e5a7e9d070360d57f85df'
DESCRIPTOR_SHA256 = '209c7f8da76a2788ce40de9e83fbca9e4370c665cf5d9803b5ea31d812f1894b'
def verify_jar(path):
if any(len(pin) != 64 for pin in (BASELINE_SHA256, RETAINED_TREE, DESCRIPTOR_SHA256)):
raise ValueError('Expected complete SHA-256 pins')
with zipfile.ZipFile(path) as jar:
names = [name for name in jar.namelist() if not name.endswith('/')]
if len(set(names)) != len(names):
raise ValueError('Duplicate DuneMenus archive entry')
if b'THE SPICE MUST FLOW' not in jar.read(OVERLAY):
raise ValueError('Compact menu markup is missing')
if hashlib.sha256(jar.read('plugin.yml')).hexdigest() != DESCRIPTOR_SHA256:
raise ValueError('DuneMenus descriptor differs outside the reviewed version')
rows = [name + '\0' + hashlib.sha256(jar.read(name)).hexdigest()
for name in sorted(names) if name not in {OVERLAY, 'plugin.yml'}]
if hashlib.sha256('\n'.join(rows).encode()).hexdigest() != RETAINED_TREE:
raise ValueError('DuneMenus changed outside the reviewed compact UI and version')
if __name__ == '__main__':
import sys
verify_jar(Path(sys.argv[1]))