mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Merge branch 'main' of https://github.com/boxgaming/qbjs
This commit is contained in:
commit
2c2b1f12da
5 changed files with 150 additions and 19 deletions
|
@ -35,21 +35,20 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
// TODO: adjust for QB
|
||||
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
|
||||
|
||||
var builtinFuncsWords = ['_alpha', '_alpha32', '_atan2', '_autodisplay', '_blue', '_blue32', '_continue', '_copyimage', '_cosh', '_d2r', '_delay', '_dest', '_dest',
|
||||
'_display', '_fontwidth', '_freeimage', '_green', '_green32', '_height', '_instrrev', '_limit', '_keyclear', '_keydown',
|
||||
var builtinFuncsWords = ['_alpha', '_alpha32', '_atan2', '_autodisplay', '_blue', '_blue32', '_continue', '_copyimage', '_cosh', '_d2r', '_delay', '_dest',
|
||||
'_display', '_fontwidth', '_freeimage', '_fullscreen', '_green', '_green32', '_height', '_instrrev', '_limit', '_keyclear', '_keydown',
|
||||
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
|
||||
'_putimage', '_r2d', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||
'_screenexists', '_sinh', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol',
|
||||
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'draw', 'exp',
|
||||
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'exp',
|
||||
'fix', 'hex', 'input', 'inkey', 'instr', 'int', 'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
||||
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr', 'str', 'swap', 'tan',
|
||||
'timer', 'ubound', 'ucase', 'val', 'varptr',
|
||||
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
|
||||
'str', 'swap', 'tan', 'timer', 'ubound', 'ucase', 'val',
|
||||
// QBJS-specific
|
||||
'export', 'import']
|
||||
//'alert', 'confirm', 'domadd', 'domcontainer', 'domcreate', 'domevent','domget', 'domgetimage', 'domremove', 'export',
|
||||
//'from', 'prompt', 'import', 'storageclear', 'storageget', 'storagekey', 'storagelength', 'storageset', 'storageremove'];
|
||||
'export', 'from', 'import']
|
||||
|
||||
var builtinConsts = ['gx_true', 'gx_false', 'gxevent_init', 'gxevent_update', 'gxevent_drawbg', 'gxevent_drawmap', 'gxevent_drawscreen',
|
||||
var builtinConsts = ['_off', '_smooth', '_stretch', '_squarepixels',
|
||||
'gx_true', 'gx_false', 'gxevent_init', 'gxevent_update', 'gxevent_drawbg', 'gxevent_drawmap', 'gxevent_drawscreen',
|
||||
'gxevent_mouseinput', 'gxevent_paintbefore', 'gxevent_paintafter', 'gxevent_collision_tile', 'gxevent_collision_entity',
|
||||
'gxevent_player_action', 'gxevent_animate_complete', 'gxanimate_loop', 'gxanimate_single', 'gxbg_stretch',
|
||||
'gxbg_scroll', 'gxbg_wrap', 'gxkey_esc', 'gxkey_1', 'gxkey_2', 'gxkey_3', 'gxkey_4', 'gxkey_5', 'gxkey_6', 'gxkey_7',
|
||||
|
|
48
gx/gx.js
48
gx/gx.js
|
@ -17,7 +17,7 @@ var GX = new function() {
|
|||
_fonts[0] = { eid:0, charSpacing:0, lineSpacing: 0};
|
||||
_fonts[1] = { eid:0, charSpacing:0, lineSpacing: 0};
|
||||
var _font_charmap = new Array(2).fill(new Array(256).fill({x:0,y:0}));
|
||||
var _fullscreenFlag = false;
|
||||
//var _fullscreenFlag = false;
|
||||
var __debug = {
|
||||
enabled: false,
|
||||
font: 1 // GX.FONT_DEFAULT
|
||||
|
@ -70,7 +70,7 @@ var GX = new function() {
|
|||
_fontCreateDefault(GX.FONT_DEFAULT);
|
||||
_fontCreateDefault(GX.FONT_DEFAULT_BLACK);
|
||||
|
||||
_fullscreenFlag = false;
|
||||
//_fullscreenFlag = false;
|
||||
__debug = {
|
||||
enabled: false,
|
||||
font: 1 // GX.FONT_DEFAULT
|
||||
|
@ -160,6 +160,35 @@ var GX = new function() {
|
|||
}
|
||||
});
|
||||
|
||||
document.addEventListener("fullscreenchange", function(event) {
|
||||
if (document.fullscreenElement) {
|
||||
_scene.prevScaleX = _scene.scaleX;
|
||||
_scene.prevScaleY = _scene.scaleY;
|
||||
var widthFactor = screen.width / _scene.width;
|
||||
var heightFactor = screen.height / _scene.height;
|
||||
var factor = Math.min(widthFactor, heightFactor);
|
||||
var offsetX = 0;
|
||||
var offsetY = 0;
|
||||
if (widthFactor > heightFactor) {
|
||||
offsetX = (screen.width - _scene.width * factor) / 2;
|
||||
}
|
||||
else {
|
||||
offsetY = (screen.height - _scene.height * factor) / 2;
|
||||
}
|
||||
|
||||
_scene.scaleX = factor;
|
||||
_scene.scaleY = factor;
|
||||
_scene.offsetX = offsetX;
|
||||
_scene.offsetY = offsetY;
|
||||
}
|
||||
else {
|
||||
_scene.scaleX = _scene.prevScaleX;
|
||||
_scene.scaleY = _scene.prevScaleY;
|
||||
_scene.offsetX = 0;
|
||||
_scene.offsetY = 0;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
_canvas.addEventListener("keyup", function(event) {
|
||||
if (_scene.active) {
|
||||
|
@ -188,6 +217,8 @@ var GX = new function() {
|
|||
_scene.y = 0;
|
||||
_scene.scaleX = 1;
|
||||
_scene.scaleY = 1;
|
||||
_scene.offsetX = 0;
|
||||
_scene.offsetY = 0;
|
||||
_scene.frame = 0;
|
||||
_scene.followMode = GX.SCENE_FOLLOW_NONE;
|
||||
_scene.followEntity = null;
|
||||
|
@ -1719,14 +1750,17 @@ var GX = new function() {
|
|||
|
||||
function _fullScreen(fullscreenFlag) {
|
||||
if (fullscreenFlag != undefined) {
|
||||
_fullscreenFlag = fullscreenFlag;
|
||||
if (fullscreenFlag) {
|
||||
document.getElementById("gx-container").requestFullscreen();
|
||||
if (_canvas.requestFullscreen) {
|
||||
_canvas.requestFullscreen();
|
||||
}
|
||||
} else {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
return _fullscreenFlag;
|
||||
}
|
||||
return (window.innerHeight == screen.height);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1846,11 +1880,11 @@ var GX = new function() {
|
|||
}
|
||||
|
||||
function _mouseX() {
|
||||
return Math.round(_mousePos.x / _scene.scaleX);
|
||||
return Math.round((_mousePos.x - _scene.offsetX) / _scene.scaleX);
|
||||
}
|
||||
|
||||
function _mouseY() {
|
||||
return Math.round(_mousePos.y / _scene.scaleY);
|
||||
return Math.round((_mousePos.y - _scene.offsetY) / _scene.scaleY);
|
||||
};
|
||||
|
||||
function _mouseButton(button) {
|
||||
|
|
36
qb.js
36
qb.js
|
@ -4,6 +4,9 @@ var QB = new function() {
|
|||
this.PREVENT_NEWLINE = Symbol("PREVENT_NEWLINE");
|
||||
this.LOCAL = Symbol("LOCAL");
|
||||
this.SESSION = Symbol("SESSION");
|
||||
this.STRETCH = Symbol("STRETCH");
|
||||
this.SQUAREPIXELS = Symbol("SQUAREPIXELS");
|
||||
this.OFF = Symbol("OFF");
|
||||
|
||||
var _strokeThickness = 2;
|
||||
var _fgColor = null;
|
||||
|
@ -120,7 +123,7 @@ var QB = new function() {
|
|||
// Access methods for std libraries
|
||||
// --------------------------------------------
|
||||
this.getImage = function(imageId) {
|
||||
return _images[imageId];
|
||||
return _images[imageId].canvas;
|
||||
};
|
||||
|
||||
// Extended QB64 Keywords
|
||||
|
@ -201,6 +204,21 @@ var QB = new function() {
|
|||
|
||||
this.sub__FreeImage = function(imageId) {
|
||||
_images[imageId] = undefined;
|
||||
};
|
||||
|
||||
this.func__FullScreen = function() {
|
||||
return GX.fullScreen();
|
||||
};
|
||||
|
||||
this.sub__FullScreen = function(mode, smooth) {
|
||||
if (mode == QB.OFF) {
|
||||
GX.fullScreen(false);
|
||||
}
|
||||
else if (mode == QB.STRETCH || mode == QB.SQUAREPIXELS) {
|
||||
// TODO: not making any distinction at present
|
||||
GX.fullScreen(true);
|
||||
}
|
||||
// TODO: implement smooth option (maybe) - the canvas does smooth scaling by default
|
||||
}
|
||||
|
||||
this.func__Green = function(rgb, imageHandle) {
|
||||
|
@ -549,6 +567,18 @@ var QB = new function() {
|
|||
return Math.atan(value);
|
||||
};
|
||||
|
||||
this.sub_Beep = function() {
|
||||
var context = new AudioContext();
|
||||
var oscillator = context.createOscillator();
|
||||
oscillator.type = "square";
|
||||
oscillator.frequency.value = 780;
|
||||
oscillator.connect(context.destination);
|
||||
oscillator.start();
|
||||
setTimeout(function () {
|
||||
oscillator.stop();
|
||||
}, 200);
|
||||
};
|
||||
|
||||
this.func_Chr = function(charCode) {
|
||||
return String.fromCharCode(charCode);
|
||||
};
|
||||
|
@ -1147,9 +1177,13 @@ var QB = new function() {
|
|||
y0 = screen.lastY + y0;
|
||||
}
|
||||
|
||||
fillColor = _color(fillColor);
|
||||
if (borderColor == undefined) {
|
||||
borderColor = fillColor;
|
||||
}
|
||||
else {
|
||||
borderColor = _color(borderColor);
|
||||
}
|
||||
|
||||
var pixelStack = [[Math.floor(x0), Math.floor(y0)]];
|
||||
|
||||
|
|
34
qb2js.js
34
qb2js.js
|
@ -489,12 +489,43 @@ var ConvertSub = null;
|
|||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertCls( args)) +");";
|
||||
} else if ( m.name == "_PutImage" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertPutImage( args)) +");";
|
||||
} else if ( m.name == "_FullScreen" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertFullScreen( args)) +");";
|
||||
} else {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertMethodParams( args)) +");";
|
||||
}
|
||||
ConvertSub = js;
|
||||
return ConvertSub;
|
||||
}
|
||||
async function func_ConvertFullScreen(args/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertFullScreen = null;
|
||||
var parts = QB.initArray([{l:1,u:0}], ''); // STRING
|
||||
var argc = 0; // INTEGER
|
||||
var mode = ''; // STRING
|
||||
mode = "QB.STRETCH";
|
||||
var doSmooth = ''; // STRING
|
||||
doSmooth = "false";
|
||||
argc = (await func_ListSplit( args, parts));
|
||||
if ( argc > 0) {
|
||||
var arg = ''; // STRING
|
||||
arg = (QB.func_UCase( QB.arrayValue(parts, [ 1]).value));
|
||||
if ( arg == "_OFF" ) {
|
||||
mode = "QB.OFF";
|
||||
} else if ( arg == "_STRETCH" ) {
|
||||
mode = "QB.STRETCH";
|
||||
} else if ( arg == "_SQUAREPIXELS" ) {
|
||||
mode = "QB.SQUAREPIXELS";
|
||||
}
|
||||
}
|
||||
if ( argc > 1) {
|
||||
if ((QB.func_UCase( QB.arrayValue(parts, [ 2]).value)) == "_SMOOTH" ) {
|
||||
doSmooth = "true";
|
||||
}
|
||||
}
|
||||
ConvertFullScreen = mode +", " + doSmooth;
|
||||
return ConvertFullScreen;
|
||||
}
|
||||
async function func_ConvertLine(args/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertLine = null;
|
||||
|
@ -2509,6 +2540,8 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "SUB", "_Display", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_FontWidth", False);
|
||||
await sub_AddQBMethod( "SUB", "_FreeImage", False);
|
||||
await sub_AddQBMethod( "SUB", "_FullScreen", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_FullScreen", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_Green", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_Green32", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_Height", False);
|
||||
|
@ -2553,6 +2586,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "Abs", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Asc", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Atn", False);
|
||||
await sub_AddQBMethod( "SUB", "Beep", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Chr$", False);
|
||||
await sub_AddQBMethod( "SUB", "Circle", False);
|
||||
await sub_AddQBMethod( "SUB", "Cls", False);
|
||||
|
|
|
@ -591,6 +591,8 @@ Function ConvertSub$ (m As Method, args As String)
|
|||
ElseIf m.name = "_PutImage" Then
|
||||
js = CallMethod(m) + "(" + ConvertPutImage(args) + ");"
|
||||
|
||||
ElseIf m.name = "_FullScreen" Then
|
||||
js = CallMethod(m) + "(" + ConvertFullScreen(args) + ");"
|
||||
Else
|
||||
'js = CallMethod(m) + "(" + ConvertExpression(args) + ");"
|
||||
js = CallMethod(m) + "(" + ConvertMethodParams(args) + ");"
|
||||
|
@ -599,6 +601,31 @@ Function ConvertSub$ (m As Method, args As String)
|
|||
ConvertSub = js
|
||||
End Function
|
||||
|
||||
Function ConvertFullScreen$ (args As String)
|
||||
ReDim parts(0) As String
|
||||
Dim argc As Integer
|
||||
Dim mode As String: mode = "QB.STRETCH"
|
||||
Dim doSmooth As String: doSmooth = "false"
|
||||
|
||||
argc = ListSplit(args, parts())
|
||||
If argc > 0 Then
|
||||
Dim arg As String
|
||||
arg = UCase$(parts(1))
|
||||
If arg = "_OFF" Then
|
||||
mode = "QB.OFF"
|
||||
ElseIf arg = "_STRETCH" Then
|
||||
mode = "QB.STRETCH"
|
||||
ElseIf arg = "_SQUAREPIXELS" Then
|
||||
mode = "QB.SQUAREPIXELS"
|
||||
End If
|
||||
End If
|
||||
If argc > 1 Then
|
||||
If UCase$(parts(2)) = "_SMOOTH" Then doSmooth = "true"
|
||||
End If
|
||||
|
||||
ConvertFullScreen = mode + ", " + doSmooth
|
||||
End Function
|
||||
|
||||
Function ConvertLine$ (args As String)
|
||||
' TODO: This does not yet handle dash patterns
|
||||
Dim firstParam As String
|
||||
|
@ -2667,6 +2694,8 @@ Sub InitQBMethods
|
|||
AddQBMethod "SUB", "_Display", False
|
||||
AddQBMethod "FUNCTION", "_FontWidth", False
|
||||
AddQBMethod "SUB", "_FreeImage", False
|
||||
AddQBMethod "SUB", "_FullScreen", False
|
||||
AddQBMethod "FUNCTION", "_FullScreen", False
|
||||
AddQBMethod "FUNCTION", "_Green", False
|
||||
AddQBMethod "FUNCTION", "_Green32", False
|
||||
AddQBMethod "FUNCTION", "_Height", False
|
||||
|
@ -2714,6 +2743,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "Abs", False
|
||||
AddQBMethod "FUNCTION", "Asc", False
|
||||
AddQBMethod "FUNCTION", "Atn", False
|
||||
AddQBMethod "SUB", "Beep", False
|
||||
AddQBMethod "FUNCTION", "Chr$", False
|
||||
AddQBMethod "SUB", "Circle", False
|
||||
AddQBMethod "SUB", "Cls", False
|
||||
|
|
Loading…
Reference in a new issue