Skip to content

Commit

Permalink
Fixing ADS and TTM play for Castaway and TurboSCI
Browse files Browse the repository at this point in the history
  • Loading branch information
xesf committed Mar 28, 2020
1 parent 8fa9bbb commit bb53c2b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getSoundFxSource(config, context, data) {
source.connect();
callback.call();
} else {
loadAudioAsync(context, `data/samples/sample${index}.aac`, (buffer) => {
loadAudioAsync(context, `data/castaway/samples/sample${index}.aac`, (buffer) => {
// this bypasses a browser issue while loading same sample in short period of time
if (!samplesSourceCache[index]) {
if (!source.bufferSource.buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createWindow() {
? 'http://localhost:8585'
: `file://${path.join(__dirname, '../build/index.html')}`
);
mainWindow.webContents.once('dom-ready', () => mainWindow.webContents.openDevTools());
// mainWindow.webContents.once('dom-ready', () => mainWindow.webContents.openDevTools());
mainWindow.on('closed', () => { mainWindow = null; });
}

Expand Down
6 changes: 6 additions & 0 deletions src/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PALETTE } from './constants';


export const RESOURCES = {
PALETTE,
};
4 changes: 4 additions & 0 deletions src/graphics/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import { RESOURCES } from '../global';

export const drawImage = (image, context, posX, posY) => {
const img = context.createImageData(image.width, image.height);
for (let p = 0; p < image.pixels.length; p += 1) {
Expand Down Expand Up @@ -62,6 +64,8 @@ export const drawPalette = (data, context) => {
context.fillStyle = getPaletteColor(c);
context.fillRect(p * 2, 0, 2, 480);
}

RESOURCES.PALETTE = data.palette;
};

export const drawScreen = (data, context) => {
Expand Down
10 changes: 5 additions & 5 deletions src/resources/bmp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PALETTE } from '../constants';
import { getString } from '../utils/string';
import { decompress } from '../compression';
import { RESOURCES } from '../global';

export function loadBMPResourceEntry(entry) {
let offset = 0;
Expand Down Expand Up @@ -61,10 +61,10 @@ export function loadBMPResourceEntry(entry) {
image.buffer[w + image.width * h] = c;
image.pixels[w + image.width * h] = {
index: c,
a: PALETTE[c].a,
r: PALETTE[c].r,
g: PALETTE[c].g,
b: PALETTE[c].b,
a: RESOURCES.PALETTE[c].a,
r: RESOURCES.PALETTE[c].r,
g: RESOURCES.PALETTE[c].g,
b: RESOURCES.PALETTE[c].b,
};
pixelIndex += 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/resources/scr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PALETTE } from '../constants';
import { getString } from '../utils/string';
import { decompress } from '../compression';
import { RESOURCES } from '../global';

export function loadSCRResourceEntry(entry) {
let offset = 0;
Expand Down Expand Up @@ -52,7 +52,7 @@ export function loadSCRResourceEntry(entry) {
c &= 0x0f;
dataIndex += 1;
}
const pal = PALETTE[c];
const pal = RESOURCES.PALETTE[c];
image.buffer[w + image.width * h] = c;
image.pixels[w + image.width * h] = {
index: c,
Expand Down
24 changes: 12 additions & 12 deletions src/scripting/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { loadResourceEntry } from '../resources';

import { drawImage, drawScreen, getPaletteColor } from '../graphics/index';
import { createAudioManager } from '../audio';
import { PALETTE } from '../constants';
import { RESOURCES } from '../global';

let tick = null;
let prevTick = Date.now();
Expand Down Expand Up @@ -161,10 +161,10 @@ const GOTO = (state, tagId) => {

const SET_COLORS = (state, fc, bc) => {
if (fc < 16) {
state.foregroundColor = PALETTE[fc];
state.foregroundColor = RESOURCES.PALETTE[fc];
}
if (bc < 16) {
state.backgroundColor = PALETTE[bc];
state.backgroundColor = RESOURCES.PALETTE[bc];
}
};

Expand Down Expand Up @@ -619,7 +619,7 @@ const STOP_SCENE = (state, sceneIdx, tagId, retries) => {
tagId,
retries,
});
console.log('STOP_SCENE', removeScenes);
// console.log('STOP_SCENE', removeScenes);
// console.log(scenes);
// remove(scenes, s => s.sceneIdx === sceneIdx && s.tagId === tagId);
// const index = scenes.indexOf(s => s.sceneIdx === sceneIdx && s.tagId === tagId);
Expand Down Expand Up @@ -794,13 +794,13 @@ const CommandType2 = {
'0x2010': STOP_SCENE,
'0x3010': RANDOM_START,
'0x3020': RANDOM_UNKNOWN_0,
'0x30ff': RANDOM_END,
'0x30FF': RANDOM_END,
'0x4000': ADS_UNKNOWN_6,
'0xf010': ADS_FADE_OUT,
'0xf200': RUN_SCRIPT,
'0xffff': END,
'0xF010': ADS_FADE_OUT,
'0xF200': RUN_SCRIPT,
'0xFFFF': END,
// CUSTOM: Added for text script
'0xfff0': END_IF,
'0xFFF0': END_IF,
};

const runScript = (state, script, main = false) => {
Expand All @@ -810,7 +810,7 @@ const runScript = (state, script, main = false) => {
for (let i = state.reentry; i < script.length; i++) {
const c = script[i];
//const type = CommandType.find(ct => ct.opcode === c.opcode);
const callback = CommandType2[`0x${c.opcode.toString(16)}`];
const callback = CommandType2[`0x${c.opcode.toString(16).padStart(4, '0').toUpperCase()}`];
if (!callback || callback === undefined) {
continue;
}
Expand Down Expand Up @@ -902,8 +902,8 @@ export const startProcess = (initialState) => {
continue: true,
frameId: null,
island: 1,
foregroundColor: PALETTE[0],
backgroundColor: PALETTE[0],
foregroundColor: RESOURCES.PALETTE[0],
backgroundColor: RESOURCES.PALETTE[0],
clip: { x: 0, y: 0, width: 640, height: 480 },
type: null,
skip: false,
Expand Down
3 changes: 1 addition & 2 deletions src/ui/components/ResourceContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';

import { loadResourceEntry } from '../../resources';

import { RESOURCES } from '../global';
import { RESOURCES } from '../../global';

import ResourceView from './ResourceView';

Expand Down Expand Up @@ -34,7 +34,6 @@ const ResourceContent = ({ res }) => {
const e = RESOURCES[`${game}-${resource}`].entries;
setEntries(e);
const entry = RESOURCES[`${game}-${resource}`].entries.find((f) => f.name === name);
console.log(entry);
setData(loadResourceEntry(entry));
}
return () => {};
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/ResourceItems.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import async from 'async';
import { preloadFileAsync } from '../../utils/preload';
import { loadResourcebyName } from '../../resources';

import { RESOURCES } from '../global';
import { RESOURCES } from '../../global';

const ResourceItems = ({ game, res }) => {
const [resource, setResource] = useState(null);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/components/ResourceView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const ResourceView = ({ entries, data }) => {
|| resType.type === 'TTM') {
const mainContext = mainCanvasRef.current.getContext('2d');
context.clearRect(0, 0, 640, 480);
mainContext.clearRect(0, 0, 640, 480);
mainContext.canvas.width = 640;
mainContext.canvas.height = 480;

startProcess({
type: resType.type,
Expand Down
2 changes: 0 additions & 2 deletions src/ui/global.js

This file was deleted.

0 comments on commit bb53c2b

Please sign in to comment.