Skip to content

Commit 2d4cba2

Browse files
committed
Merge remote-tracking branch 'fsvieira/develop' into custom-components
2 parents 711dbea + 24f8956 commit 2d4cba2

7 files changed

Lines changed: 811 additions & 38233 deletions

File tree

core/components/GameScreen.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GameScreen extends Component {
1111
}
1212

1313
static resize (proportionWidth, proportionHeight) {
14-
const mainElement = $_(Monogatari.selector).get (0);
14+
const mainElement = $_('body').get (0);
1515

1616
const mainWidth = mainElement.offsetWidth;
1717
const mainHeight = mainElement.offsetHeight;
@@ -51,13 +51,26 @@ class GameScreen extends Component {
5151
});
5252

5353
const forceAspectRatio = Monogatari.setting ('ForceAspectRatio');
54+
let forceAspectRatioFlag = true;
5455

55-
if (forceAspectRatio) {
56+
switch (forceAspectRatio) {
57+
case 'Visuals':
58+
$_('[data-content="visuals"]').addClass('forceAspectRatio');
59+
break;
60+
61+
case 'Global':
62+
$_(Monogatari.selector).addClass('forceAspectRatio');
63+
break;
64+
65+
default:
66+
forceAspectRatioFlag = false;
67+
}
68+
69+
if (forceAspectRatioFlag) {
5670
const [w, h] = Monogatari.setting ('AspectRatio').split (':');
5771
const proportionWidth = parseInt(w);
5872
const proportionHeight = parseInt(h);
59-
60-
$_('[data-content="visuals"]').addClass('forceAspectRatio');
73+
6174
GameScreen.resize(proportionWidth, proportionHeight);
6275
$_(window).on('resize', () => GameScreen.resize(proportionWidth, proportionHeight));
6376
}

core/components/game-screen/index.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@ import { Monogatari } from './../../monogatari';
33

44
class GameScreen extends ScreenComponent {
55

6-
7-
// static resize (proportionWidth, proportionHeight) {
8-
// const mainElement = $_(Monogatari.selector).get (0);
9-
10-
// const mainWidth = mainElement.offsetWidth;
11-
// const mainHeight = mainElement.offsetHeight;
12-
13-
// const h = Math.floor (mainWidth * (proportionHeight/proportionWidth));
14-
// let widthCss = '100%';
15-
// let heightCss = '100%';
16-
// let marginTopCss = 0;
17-
18-
// if (h <= mainHeight) {
19-
// const marginTop = Math.floor ((mainHeight - h)/2);
20-
// marginTopCss = marginTop + 'px';
21-
// heightCss = h + 'px';
22-
23-
// }
24-
// else {
25-
// const w = Math.floor (mainHeight * (proportionWidth/proportionHeight));
26-
// widthCss = w + 'px';
27-
// }
28-
29-
// $_('.forceAspectRatio').style ({
30-
// width: widthCss,
31-
// height: heightCss,
32-
// marginTop: marginTopCss
33-
// });
34-
// }
35-
366
static bind (selector) {
377
this.engine.on ('click', '[data-screen="game"] *:not([data-choice])', function () {
388
Monogatari.debug.debug ('Next Statement Listener');
@@ -44,18 +14,6 @@ class GameScreen extends ScreenComponent {
4414
});
4515
});
4616

47-
// const forceAspectRatio = Monogatari.setting ('ForceAspectRatio');
48-
49-
// if (forceAspectRatio) {
50-
// const [w, h] = Monogatari.setting ('AspectRatio').split (':');
51-
// const proportionWidth = parseInt(w);
52-
// const proportionHeight = parseInt(h);
53-
54-
// $_('[data-content="visuals"]').addClass('forceAspectRatio');
55-
// GameScreen.resize(proportionWidth, proportionHeight);
56-
// $_(window).on('resize', () => GameScreen.resize(proportionWidth, proportionHeight));
57-
// }
58-
5917
Monogatari.registerListener ('back', {
6018
keys: 'left',
6119
callback: () => {

core/monogatari.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,11 +2130,41 @@ class Monogatari {
21302130
});
21312131
}
21322132

2133+
static resize (element, proportionWidth, proportionHeight) {
2134+
const mainElement = $_('body').get (0);
2135+
2136+
const mainWidth = mainElement.offsetWidth;
2137+
const mainHeight = mainElement.offsetHeight;
2138+
2139+
const h = Math.floor (mainWidth * (proportionHeight/proportionWidth));
2140+
let widthCss = '100%';
2141+
let heightCss = '100%';
2142+
let marginTopCss = 0;
2143+
2144+
if (h <= mainHeight) {
2145+
const marginTop = Math.floor ((mainHeight - h)/2);
2146+
marginTopCss = marginTop + 'px';
2147+
heightCss = h + 'px';
2148+
2149+
}
2150+
else {
2151+
const w = Math.floor (mainHeight * (proportionWidth/proportionHeight));
2152+
widthCss = w + 'px';
2153+
}
2154+
2155+
$_('.forceAspectRatio').style ({
2156+
width: widthCss,
2157+
height: heightCss,
2158+
marginTop: marginTopCss
2159+
});
2160+
}
2161+
21332162
/**
21342163
* Every event listener should be binded in this function.
21352164
*/
21362165
static bind (selector) {
21372166

2167+
21382168
// Add the orientation checker in case that a specific orientation was
21392169
// defined.
21402170
if (this.setting ('Orientation') !== 'any' && Platform.mobile ()) {
@@ -2219,6 +2249,31 @@ class Monogatari {
22192249
}
22202250
});
22212251

2252+
const forceAspectRatio = Monogatari.setting ('ForceAspectRatio');
2253+
let forceAspectRatioFlag = true;
2254+
2255+
switch (forceAspectRatio) {
2256+
case 'Visuals':
2257+
$_('[data-content="visuals"]').addClass('forceAspectRatio');
2258+
break;
2259+
2260+
case 'Global':
2261+
this.element ().parent ().addClass('forceAspectRatio');
2262+
break;
2263+
2264+
default:
2265+
forceAspectRatioFlag = false;
2266+
}
2267+
2268+
if (forceAspectRatioFlag) {
2269+
const [w, h] = Monogatari.setting ('AspectRatio').split (':');
2270+
const proportionWidth = parseInt(w);
2271+
const proportionHeight = parseInt(h);
2272+
2273+
this.resize(proportionWidth, proportionHeight);
2274+
$_(window).on ('resize', () => this.resize(proportionWidth, proportionHeight));
2275+
}
2276+
22222277
const promises = [];
22232278

22242279
for (const component of this.components ()) {

dist/engine/monogatari.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)