Skip to content

Dev #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2020
Merged

Dev #82

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions dist/plugins/iwsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,46 @@ const EasyCoder_IWSY = {

const lino = compiler.getLino();
const action = compiler.nextToken();
if ([`init`, `show`].includes(action)) {
compiler.next();
compiler.addCommand({
domain: `iwsy`,
keyword: `iwsy`,
lino,
action
});
return true;
}
switch (action) {
case `load`:
if (compiler.nextIsSymbol()) {
const playerRecord = compiler.getSymbolRecord();
if (playerRecord.keyword === `div`) {
const script = compiler.getNextValue();
compiler.addCommand({
domain: `iwsy`,
keyword: `iwsy`,
lino,
action,
player: playerRecord.name,
script
});
return true;
}
}
break;
case `init`:
compiler.next();
compiler.addCommand({
domain: `iwsy`,
keyword: `iwsy`,
lino,
action
});
return true;
case `goto`:
const target = compiler.getNextValue();
compiler.addCommand({
domain: `iwsy`,
keyword: `iwsy`,
lino,
action,
target
});
return true;
default:
break;
}
return false;
},

Expand All @@ -33,8 +63,18 @@ const EasyCoder_IWSY = {
function () {
program.run(command.pc + 1);
});
return 0;
case `load`:
const playerRecord = program.getSymbolRecord(command.player);
const player = playerRecord.element[playerRecord.index];
player.innerHTML = ``;
player.style.background = `none`;
player.style.border = `none`;
const script = program.getValue(command.script);
EasyCoder.iwsyGotoStep = IWSY(player, JSON.parse(script));
break;
case `show`:
case `goto`:
EasyCoder.iwsyGotoStep(program.getValue(command.target));
break;
}
return command.pc + 1;
Expand Down
195 changes: 80 additions & 115 deletions iwsy/iwsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,40 @@ const IWSY = (container, script) => {
block.element = element;
element.style[`position`] = `absolute`;
element.style[`opacity`] = `0.0`;
let val = properties.blockLeft;
let val = properties.left;
if (!isNaN(val)) {
val *= w;
}
element.style[`left`] = val;
val = properties.blockTop;
val = properties.top;
if (!isNaN(val)) {
val *= h;
}
element.style[`top`] = val;
val = properties.blockWidth;
val = properties.width;
if (!isNaN(val)) {
val *= w;
val = `${val * w}px`;
}
element.style[`width`] = `${val}px`;
val = properties.blockHeight;
element.style[`width`] = val;
val = properties.height;
if (!isNaN(val)) {
val *= h;
val = `${val * h}px`;
}
element.style[`height`] = `${val}px`;
element.style[`background`] = properties.blockBackground;
element.style[`border`] = properties.blockBorder;
element.style[`height`] = val;
element.style[`background`] = properties.background;
element.style[`border`] = properties.border;
container.appendChild(element);
val = properties.textMarginLeft;
if (!isNaN(val)) {
val *= w;
val = `${val * w}px`;
}
element.style[`width`] = val;
const marginLeft = val;
val = properties.textMarginTop;
if (!isNaN(val)) {
val *= h;
val = `${val * h}px`;
}
element.style[`height`] = val;
const marginTop = val;
const inner = document.createElement(`div`);
inner.style[`position`] = `absolute`;
Expand Down Expand Up @@ -176,30 +178,30 @@ const IWSY = (container, script) => {
block.element = element;
element.style[`position`] = `absolute`;
element.style[`opacity`] = `0.0`;
let val = properties.blockLeft;
let val = properties.left;
if (!isNaN(val)) {
val *= w;
}
element.style[`left`] = val;
val = properties.blockTop;
val = properties.top;
if (!isNaN(val)) {
val *= h;
}
element.style[`top`] = val;
element.style[`top`] = val;
val = properties.blockWidth;
val = properties.width;
if (!isNaN(val)) {
val *= w;
val = `${val * w}px`;
}
element.style[`width`] = `${val}px`;
val = properties.blockHeight;
element.style[`width`] = val;
val = properties.height;
if (!isNaN(val)) {
val *= h;
val = `${val * h}px`;
}
element.style[`height`] = `${val}px`;
element.style[`background`] = properties.blockBackground;
element.style[`border`] = properties.blockBorder;
element.style[`border-radius`] = properties.blockBorderRadius;
element.style[`height`] = val;
element.style[`background`] = properties.background;
element.style[`border`] = properties.border;
element.style[`border-radius`] = properties.borderRadius;
container.appendChild(element);
if (script.speed === `scan`) {
element.style.opacity = 0;
Expand Down Expand Up @@ -634,6 +636,13 @@ const IWSY = (container, script) => {
}
};

// Go to a specified step number
const gotoStep = (target) => {
script.scanTarget = target;
script.singleStep = true;
scan();
};

// Load a plugin action
const load = step => {
if (script.speed === `scan`) {
Expand All @@ -652,7 +661,7 @@ const IWSY = (container, script) => {
}
};

// Initialize the presenttion
// Initialize the presentation
const init = step => {
if (step.title) {
document.title = step.title;
Expand All @@ -677,6 +686,16 @@ const IWSY = (container, script) => {
step.next();
};

// Chain to another presentation
const chain = step => {
step.next()
};

// Embed another presentation
const embed = step => {
step.next()
};

const actions = {
init,
setcontent,
Expand All @@ -689,7 +708,9 @@ const IWSY = (container, script) => {
crossfade,
transition,
goto,
load
load,
chain,
embed
};

// Process a single step
Expand Down Expand Up @@ -722,104 +743,48 @@ const IWSY = (container, script) => {
handler(step);
};

// Initialization
const setup = () => {
container.innerHTML = ``;
document.removeEventListener(`click`, init);
if (mode === `auto`) {
document.addEventListener(`click`, onClick);
}
document.onkeydown = null;
script.container = container;
container.style.position = `relative`;
container.style.overflow = `hidden`;
container.style.cursor = 'none';
container.style[`background-size`] = `cover`;
script.speed = `normal`;
script.labels = {};
for (const [index, step] of script.steps.entries()) {
step.index = index;
step.script = script;
if (typeof step.label !== `undefined`) {
script.labels[step.label] = index;
}
if (index < script.steps.length - 1) {
step.next = () => {
container.innerHTML = ``;
document.removeEventListener(`click`, init);
if (mode === `auto`) {
document.addEventListener(`click`, onClick);
}
document.onkeydown = null;
script.container = container;
container.style.position = `relative`;
container.style.overflow = `hidden`;
container.style.cursor = 'none';
container.style[`background-size`] = `cover`;
script.speed = `normal`;
script.singleStep = true;
script.labels = {};
for (const [index, step] of script.steps.entries()) {
step.index = index;
step.script = script;
if (typeof step.label !== `undefined`) {
script.labels[step.label] = index;
}
if (index < script.steps.length - 1) {
step.next = () => {
if (script.singleStep && script.speed != `scan`) {
console.log(`Single-step`);
} else {
const next = step.index + 1;
setTimeout(() => {
doStep(script.steps[next]);
}, 0);
}
}
else {
step.next = () => {
console.log(`Step ${index + 1}: Finished`);
container.style.cursor = 'pointer';
}
};
}
IWSY.plugins = {};
initBlocks();
preloadImages();
doStep(script.steps[0]);
};

// Wait for a click/tap or a keypress to start
document.addEventListener(`click`, init);
document.onkeydown = function (event) {
if (event.code === `Enter`) {
mode = `auto`;
}
setup();
return true;
};
};

window.onload = () => {
const createCORSRequest = (url) => {
let xhr = new XMLHttpRequest();
if (`withCredentials` in xhr) {

// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(`GET`, url, true);

} else if (typeof XDomainRequest != `undefined`) {

// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(`GET`, url);

} else {

// Otherwise, CORS is not supported by the browser.
xhr = null;

}
return xhr;
};

const scriptElement = document.getElementById(`iwsy-script`);
if (scriptElement) {
const request = createCORSRequest(`${scriptElement.innerText}?v=${Math.floor(Date.now())}`);
if (!request) {
throw Error(`Unable to access the JSON script`);
}

request.onload = () => {
if (200 <= request.status && request.status < 400) {
const script = JSON.parse(request.responseText);
IWSY(document.getElementById(`iwsy-container`), script);
} else {
throw Error(`Unable to access the JSON script`);
else {
step.next = () => {
console.log(`Step ${index + 1}: Finished`);
container.style.cursor = 'pointer';
}
};

request.onerror = () => {
throw Error(`Unable to access the JSON script`);
};

request.send();
}
IWSY.plugins = {};
initBlocks();
preloadImages();
doStep(script.steps[0]);
return gotoStep;
};
Loading