Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git@github.com:gilangcp/VN-Engine.git

Conflicts:
	stateManager.js
	vnEngine.js
  • Loading branch information...
commit b6f3b3ea7bb0f98b6ab5dfa23e6a19dcb5f11e2e 2 parents 5639d4d + bc7942f
@gilangcp authored
Showing with 98 additions and 49 deletions.
  1. +31 −29 stateManager.js
  2. +67 −20 vnEngine.js
View
60 stateManager.js
@@ -1,4 +1,5 @@
function StateManager(){
+ self =this;
this.speakTextDisplayObject = undefined;
this.ScreenStatus = 0;
this.noCheckScriptFlag =false;
@@ -104,17 +105,15 @@ function StateManager(){
state[no] = {
NO :no,
TIME :time,
- SC :this.scriptCounter,
- TSQ :this.tempScriptQueue,
- TSC :this.tempScriptCounter,
- JLL :this.jumpLabelList,
- FL :this.flagList,
- DFL :this.defaultflagList,
- BGM :this.bgm,
- CHR :this.displayCharacterList,
- BGI :this.backgroundImage,
- SCH :this.speakTextDisplayObject.text,
- SNA :vnEngine.stage.getChildAt(vnEngine.stage.getChildIndex(this.speakTextDisplayObject)-1).text
+ SC :self.scriptCounter,
+ JLL :self.jumpLabelList,
+ FL :self.flagList,
+ DFL :self.defaultflagList,
+ BGM :self.bgm,
+ CHR :self.displayCharacterList,
+ BGI :self.backgroundImage,
+ SCH :self.speakTextDisplayObject.text,
+ SNA :vnEngine.stage.getChildAt(vnEngine.stage.getChildIndex(self.speakTextDisplayObject)-1).text
};
localStorage.setItem("state",JSON.stringify(state));
return state[no];
@@ -129,16 +128,29 @@ function StateManager(){
}
this.loadState = function(state){
- console.log("Loading state");
this.jumpLabelList = state.JLL;
this.flagList = state.FL;
this.defaultflagList = state.DFL;
vnEngine.soundController.playBGM(state.BGM);
- vnEngine.stateManager.ScreenStatus="game";
-
+ self.setScreenStatus("game");
vnEngine.graphicsManager.changeBackground(state.BGI, function(){
+ if(self.getOldScreenStatus() == "MAIN_MENU"){
+ vnEngine.graphicsManager.createDialogBox();
+ self.speakTextDisplayObject = undefined;
+ vnEngine.speak(state.SCH,state.SNA);
+ }
+ else{
+ vnEngine.speak(state.SCH,state.SNA);
+ //Remove right click menu
+ vnEngine.stateManager.noCheckScriptFlag = vnEngine.stateManager.tempState;
+ vnEngine.stage.removeChildAt(vnEngine.stage.getNumChildren()-1);
+ if(vnEngine.stage.getChildAt(vnEngine.stage.getNumChildren()-1).clickable == false){
+ vnEngine.stage.getChildAt(vnEngine.stage.getNumChildren()-1).clickable = true;
+ }
+ }
+
if(state.CHR.left!= undefined){
vnEngine.graphicsManager.hideCharacter("left");
vnEngine.graphicsManager.showCharacter(state.CHR.left,"left");
@@ -160,29 +172,19 @@ function StateManager(){
vnEngine.graphicsManager.hideCharacter("center");
}
- vnEngine.stateManager.tempScriptQueue = state.TSQ;
- if(vnEngine.stateManager.tempScriptCounter >0){
- vnEngine.stateManager.tempScriptCounter = state.TSC;
- }
-
- vnEngine.stateManager.speakTextDisplayObject.text = state.SCH;
- vnEngine.stage.getChildAt(vnEngine.stage.getChildIndex(vnEngine.stateManager.speakTextDisplayObject)-1).text = state.SNA;
vnEngine.stateManager.scriptCounter = state.SC;
-
-
- //Remove right click menu
- vnEngine.stateManager.noCheckScriptFlag = vnEngine.stateManager.tempState;
- vnEngine.stage.removeChildAt(vnEngine.stage.getNumChildren()-1);
- if(vnEngine.stage.getChildAt(vnEngine.stage.getNumChildren()-1).clickable == false){
- vnEngine.stage.getChildAt(vnEngine.stage.getNumChildren()-1).clickable = true;
+
+ if(vnEngine.stage.getChildAt(vnEngine.stage.getNumChildren()-1).isOption ==true){
+ vnEngine.stateManager.noCheckScriptFlag = false;
+ vnEngine.stage.removeChildAt(vnEngine.stage.getNumChildren()-1);
}
-
//Option
if(script[vnEngine.stateManager.scriptCounter-1].type == "option"){
vnEngine.stateManager.scriptCounter--;
vnEngine.checkScript();
}
+ console.log(vnEngine.stateManager.scriptCounter);
console.log("state Loaded");
});
}
View
87 vnEngine.js
@@ -117,17 +117,18 @@ function vnEngine(){
this.initGameEnvirontment = function(){
- this.stateManager.ScreenStatus ="game";
- this.graphicsManager.createDialogBox();
+ this.stateManager.ScreenStatus="game";
+ this.graphicsManager.createDialogBox(
+ function(){
+ vnEngine.checkScript();
+ }
+ );
}
//Nantinya fungsi ini akan mengatur cepat jalanya script +
//Memunculkan menu ketika klik kanan
this.checkNextScript = function(ev){
- console.log("masuk sini");
- console.log(ev);
- console.log(vnEngine.stateManager.getScreenStatus());
if (ev.nativeEvent.which == 3 || ev.nativeEvent.button == 2 ){
if(vnEngine.stateManager.getScreenStatus() == "rightClickMenu"){
vnEngine.stateManager.noCheckScriptFlag = vnEngine.stateManager.tempState;
@@ -152,6 +153,8 @@ function vnEngine(){
//Menjalankan Script selanjutnya
//bertugas memilah & menjalankan perintah dari script
this.checkScript = function(scriptArray){
+ console.log("checkScript");
+ console.log(this.stateManager.tempScriptQueue);
if(scriptArray != undefined){
this.stateManager.tempScriptQueue.splice(0,this.stateManager.tempScriptQueue.length);
if(scriptArray.length == undefined){
@@ -180,7 +183,7 @@ function vnEngine(){
//bertugas memilah & menjalankan perintah dari script
this.parseScript = function(script,scriptCounter){
if(scriptCounter-1<script.length){
- console.log(scriptCounter-1 + " " + script[scriptCounter-1].type);
+ console.log(scriptCounter-1 + " " + script[scriptCounter-1].type );
switch(script[scriptCounter-1].type){
case 'initMenu' :
vnEngine.initMenu();
@@ -247,7 +250,7 @@ function vnEngine(){
}
}
- this.initSaveLoadMenu = function(type){
+ this.initSaveLoadMenu = function(type,isInMainMenu){
var container = new Container();
container.clickable =true;
var res = vnEngine.resourceManager.getResource("save").img;
@@ -298,9 +301,22 @@ function vnEngine(){
}
vnEngine.stage.removeChild(container);
+
//load State
+
if(e.target.state){
- vnEngine.stateManager.loadState(e.target.state);
+ if(e.target.isInMainMenu){
+ if(e.target.isInMainMenu.target.parent.parent.isContainer == "true"){
+ vnEngine.stage.removeChild(e.target.isInMainMenu.target.parent.parent);
+ }
+ else{
+ vnEngine.stage.removeChild(e.target.isInMainMenu.target.parent);
+ }
+ vnEngine.stateManager.loadState(e.target.state);
+ }
+ else{
+ vnEngine.stateManager.loadState(e.target.state);
+ }
}
else{
alert("slot Empty");
@@ -313,20 +329,25 @@ function vnEngine(){
for(var i =1 ; i < 9;i++){
if(state[i-1] == undefined){
var saveLoadDataButton = new Button("No Data",x,y,bgLayerW *8/10,30 );
+ saveLoadDataButton.setTextAlign("left");
saveLoadDataButton.no = i-1;
saveLoadDataButton.onClickListener = this.saveLoadButtonClickListener;
+ saveLoadDataButton.isInMainMenu = isInMainMenu;
}
else{
if(state[i-1].SNA.length >20){
- var speak = state[i-1].SCH +' :'+state[i-1].SNA.substring(0,20) + '...';
+ var speak = state[i-1].SCH +' : '+state[i-1].SNA.substring(0,20) + '...';
}
else{
- var speak = state[i-1].SCH +' :'+state[i-1].SNA;
+ var speak = state[i-1].SCH +' : '+state[i-1].SNA;
}
var saveLoadDataButton = new Button(state[i-1].TIME + ' '+speak ,x,y,bgLayerW *8/10,30);
+ saveLoadDataButton.setTextAlign("left");
saveLoadDataButton.state = state[i-1];
saveLoadDataButton.no = i-1;
saveLoadDataButton.onClickListener = this.saveLoadButtonClickListener;
+ saveLoadDataButton.isInMainMenu = isInMainMenu;
+
}
y+=32;
saveLoadButtonContainer.addChild(saveLoadDataButton);
@@ -365,7 +386,7 @@ function vnEngine(){
vnEngine.stage.removeAllChildren();
vnEngine.stateManager.clearAllState();
- vnEngine.stateManager.setScreenStatus("menu");
+ vnEngine.stateManager.setScreenStatus("MAIN_MENU");
var res = vnEngine.resourceManager.getResource("menu").img;
var container = new Container();
container.clickable = true;
@@ -393,9 +414,9 @@ function vnEngine(){
}
var loadButton = new Button("Load",0, y+40, this.canvas.width,30);
- loadButton.onClickListener = function(){
+ loadButton.onClickListener = function(e){
container.clickable = false;
- vnEngine.initSaveLoadMenu();
+ vnEngine.initSaveLoadMenu("load",e);
}
var settingsButton = new Button("Settings",0, y+80, this.canvas.width,30);
settingsButton.onClickListener = function(){
@@ -576,6 +597,7 @@ function vnEngine(){
var heightGenap = (this.canvas.height - (1/4 * this.canvas.height))*(2/4);
var container = new Container();
container.clickable = true;
+ container.isOption = true;
var data;
var onClickListenerFunction = function(e){
@@ -643,6 +665,8 @@ function arrayIndexOf(array, obj,value) {
function Button(text,x,y,width,height){
+ var self = this;
+ this.align = "center";
var container = new Container();
container.onClickListener = undefined;
var optionRect = new Graphics();
@@ -666,7 +690,21 @@ function Button(text,x,y,width,height){
container.setText = function(text){
txt.text = text;
- txt.x = width/2 - txt.getMeasuredWidth()/2+x;
+ self.setTextAlign(self.align);
+ }
+
+ container.setTextAlign=function(align){
+ switch(align){
+ case 'left':
+ txt.x = x+10;
+ break;
+ case 'center':
+ txt.x = width/2 - txt.getMeasuredWidth()/2+x;
+ break
+ case 'right':
+ txt.x = width - txt.getMeasuredWidth -10;
+ break;
+ }
}
container.onMouseOver = function(e){
@@ -688,7 +726,7 @@ function Button(text,x,y,width,height){
}
}
container.onClick =function(e){
- if(e.target.parent.clickable || e.target.clickable){
+ if((e.target.parent.clickable || e.target.clickable)&&!(e.nativeEvent.which == 3 || e.nativeEvent.button == 2 )){
container.onMouseOut(e);
if(container.onClickListener!=undefined )
{
@@ -710,10 +748,10 @@ function GraphicsManager(){
bitmap.x =0;
bitmap.y = 0;
bitmap.isBackground = true;
- if(vnEngine.stateManager.getScreenStatus() =="game" || vnEngine.stateManager.getScreenStatus() =="rightClickMenu"){
+ if(vnEngine.stateManager.getScreenStatus() =="game" || vnEngine.stateManager.getScreenStatus() =="menu"){
bitmap.onClick = vnEngine.checkNextScript;
}
-
+ console.log(vnEngine.stage.getNumChildren());
if(vnEngine.stage.getNumChildren() >0){
if(vnEngine.stage.getChildAt(0).isBackground){
vnEngine.stateManager.noCheckScriptFlag = true;
@@ -740,7 +778,14 @@ function GraphicsManager(){
}
else{
vnEngine.stage.addChild(bitmap);
- Tween.get(bitmap).to({alpha:0}).to({alpha:1},300);
+ if(callback == undefined){
+ Tween.get(bitmap).to({alpha:0}).to({alpha:1},300);
+ }
+ else{
+ Tween.get(bitmap).to({alpha:0}).to({alpha:1},300)
+ .call(function() {
+ callback();} );
+ }
}
}
@@ -795,7 +840,7 @@ function GraphicsManager(){
}
}
- this.createDialogBox = function(){
+ this.createDialogBox = function(run){
var textRect = new Graphics();
textRect.beginFill(Graphics.getRGB(0,0,0,0.5));
textRect.drawRect(0,vnEngine.canvas.height - (1/4 * vnEngine.canvas.height) , vnEngine.canvas.width , 1/4 * vnEngine.canvas.height);
@@ -803,7 +848,9 @@ function GraphicsManager(){
var shape = new Shape(textRect);
shape.onClick = vnEngine.checkNextScript;
vnEngine.stage.addChild(shape);
- vnEngine.checkScript();
+ if(run!=undefined){
+ run();
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.