Files
06web/build.gradle
T
Dark98 02c3d8fb10 feat(web-audio): implement Class56 MIDI player with FluidSynth and TimGM6mb.sf2
Enables authentic General MIDI music playback in `2006Scape-Web` over both HTTP and HTTPS by implementing the missing `Class56_Sub1_Sub1` web adapter and wiring `js-synthesizer` (`libfluidsynth-2.3.0.js`) with the `TimGM6mb.sf2` SoundFont.

### Java MIDI Pipeline Bridge
- `Class56_Sub1_Sub1.java`:
  - Added `org.scape2006.web` implementation of `Class56` forwarding `method827`, `method828`, `method830`, `method831`, `method832`, and `method833` to `DesktopHooks.playMidiBytes`, `setSignlinkVolume`, and `stopSignlinkMidi`.
- `build.gradle`:
  - Patched `Game.constructMusic()` in `syncSharedSources` to instantiate `new Class56_Sub1_Sub1()` directly instead of `Class.forName("Class56_Sub1_Sub1").newInstance()`, preventing `musicIsntNull()` from returning `false`.

### FluidSynth Web Audio & Caching
- `src/main/webapp/libfluidsynth-2.3.0.js`, `js-synthesizer.min.js`, `TimGM6mb.sf2`:
  - Bundled FluidSynth WASM/JS synthesizer and General MIDI SoundFont (`5.8M`) locally for offline and plain-HTTP LAN compatibility.
- `src/main/webapp/index.html`:
  - Wired `window.scapeWebAudio` (`ensureFluidSynth`, `playMidi`, `setMidiVolume`, `stopMidi`) to load `TimGM6mb.sf2`, loop tracks via `setPlayerLoop(-1)`, and resume pending MIDI on first user gesture.
- `src/main/webapp/sw.js`:
  - Added `libfluidsynth-2.3.0.js`, `js-synthesizer.min.js`, and `TimGM6mb.sf2` to `SHELL_ASSETS` and bumped `CACHE_VERSION` to `2006scape-web-v5`.
2026-12-01 14:53:04 +00:00

132 lines
4.0 KiB
Groovy

plugins {
id 'java'
id 'org.teavm' version '0.10.2'
}
group = 'org.scape2006.web'
version = '1.0.0'
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
repositories {
mavenCentral()
}
def findClientDir(String subpath) {
def candidates = [
file("../2006Scape/2006Scape Client/${subpath}"),
file("../../2006Scape/2006Scape Client/${subpath}"),
file("../2006Scape Client/${subpath}")
]
for (cand in candidates) {
if (cand.exists()) return cand
}
return file("../2006Scape/2006Scape Client/${subpath}")
}
def sharedClientSrc = findClientDir("src/main/java")
def sharedClientRes = findClientDir("src/main/resources")
def sharedClientDir = layout.buildDirectory.dir("generated/sources/sharedClient/java")
def syncSharedSources = tasks.register('syncSharedSources') {
inputs.dir(sharedClientSrc)
outputs.dir(sharedClientDir)
doLast {
def targetPkgDir = file("${sharedClientDir.get().asFile}/org/scape2006/web")
targetPkgDir.deleteDir()
targetPkgDir.mkdirs()
def excluded = [
'RSApplet.java', 'RSImageProducer.java', 'RSFrame.java',
'Main.java', 'LocalGame.java', 'Class56_Sub1_Sub1.java',
'DesktopHooks.java', 'AndroidHooks.java', 'DesktopHd317Renderer.java',
'SoundPlayer.java', 'Midi.java', 'Client.java',
'RSSocket.java', 'Signlink.java', 'Decompressor.java',
'ExternalPluginLoader.java'
] as Set
fileTree(sharedClientSrc).visit { element ->
if (element.directory) return
if (excluded.contains(element.name)) return
def dest = new File(targetPkgDir, element.name)
def src = element.file.text
src = src.replace('java.net.Socket', 'org.scape2006.web.net.Socket')
src = src.replace('java.net.InetAddress', 'org.scape2006.web.net.InetAddress')
src = src.replace('java.net.InetSocketAddress', 'org.scape2006.web.net.InetSocketAddress')
if (element.name == 'Game.java') {
src = src.replace('Signlink.reporterror("glfc_ex "', 'Signlink.reporterror("glfc_ex " + _ex + " | "')
src = src.replace('(Class56) Class.forName("Class56_Sub1_Sub1").newInstance()', 'new Class56_Sub1_Sub1()')
}
dest.text = "package org.scape2006.web;\n" + src
}
}
}
sourceSets {
main {
java {
srcDirs = ['src/main/java', sharedClientDir]
}
resources {
srcDirs = ['src/main/resources', sharedClientRes]
}
}
}
tasks.named('compileJava').configure {
dependsOn syncSharedSources
options.encoding = 'UTF-8'
}
dependencies {
implementation teavm.libs.jso
implementation teavm.libs.jsoApis
compileOnly 'org.teavm:teavm-classlib:0.10.2'
compileOnly 'org.teavm:teavm-core:0.10.2'
}
teavm {
all {
mainClass = 'org.scape2006.web.WebLauncher'
}
js {
addedToWebApp = true
targetFileName = 'client.js'
obfuscated = false
sourceMap = true
}
}
tasks.named('generateJavaScript').configure {
doLast {
def jsFile = file("${buildDir}/generated/teavm/js/js/client.js")
if (!jsFile.exists()) {
jsFile = file("${buildDir}/generated/teavm/js/client.js")
}
if (jsFile.exists()) {
def text = jsFile.text
def target = '$rt_createMultiArrayImpl = (cls, arrays, dimensions, start) => {'
if (text.contains(target)) {
jsFile.text = text.replace(target, target + ' start = start | 0;')
}
}
}
}
tasks.register('dist', Copy) {
dependsOn 'generateJavaScript'
from('src/main/webapp')
from(sharedClientRes) {
include 'hud_minimap_bezel.png', 'hud_minimap_hole.png', 'hud_chat_frame.png', 'navbar*.gif'
}
from(layout.buildDirectory.dir('generated/teavm/js')) {
into 'js'
}
into layout.buildDirectory.dir('dist')
}
tasks.named('build').configure {
dependsOn 'dist'
}