Skip to content

Commit

Permalink
Template Method Pattern 적용
Browse files Browse the repository at this point in the history
1. Template Method Pattern
2. AbstractResult Class, CouresResult Class, MusicResult Class
3. Because there are many duplicate methods and there is a lot of code duplication, we write the common part of the superclass and add the rest in the subclass.
  • Loading branch information
HweongWoo committed Jun 9, 2018
1 parent 2a77cbc commit a4ed48a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 127 deletions.
5 changes: 5 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ eclipse.preferences.version=1
encoding//src/bms/player/beatoraja/pattern/NoteShuffleModifier.java=UTF-8
encoding//src/bms/player/beatoraja/play/BMSPlayer.java=UTF-8
encoding//src/bms/player/beatoraja/play/PracticeConfiguration.java=UTF-8
encoding//src/bms/player/beatoraja/result/AbstractResult.java=UTF-8
encoding//src/bms/player/beatoraja/result/CourseResult.java=UTF-8
encoding//src/bms/player/beatoraja/result/CourseResultSkin.java=UTF-8
encoding//src/bms/player/beatoraja/result/MusicResult.java=UTF-8
encoding//src/bms/player/beatoraja/result/MusicResultSkin.java=UTF-8
encoding//src/bms/player/beatoraja/skin/lr2/LR2SkinCSVLoader.java=UTF-8
5 changes: 4 additions & 1 deletion src/bms/player/beatoraja/result/AbstractResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
import bms.player.beatoraja.IRScoreData;
import bms.player.beatoraja.MainController;
import bms.player.beatoraja.MainState;
import bms.player.beatoraja.PlayerResource;
import bms.player.beatoraja.MainState.SoundType;
import bms.player.beatoraja.result.AbstractResult.ReplayStatus;

public abstract class AbstractResult extends MainState {

/**
* 状態
* �듁�뀑
*/
protected int state;

Expand Down
61 changes: 11 additions & 50 deletions src/bms/player/beatoraja/result/CourseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@ public CourseResult(MainController main) {
super(main);
}

public void create() {
final PlayerResource resource = main.getPlayerResource();

for(int i = 0;i < REPLAY_SIZE;i++) {
saveReplay[i] = main.getPlayDataAccessor().existsReplayData(resource.getCourseBMSModels(),
resource.getPlayerConfig().getLnmode(), i ,resource.getConstraint()) ? ReplayStatus.EXIST : ReplayStatus.NOT_EXIST ;
}

setSound(SOUND_CLEAR, "course_clear.wav", SoundType.SOUND,false);
setSound(SOUND_FAIL, "course_fail.wav", SoundType.SOUND, false);
setSound(SOUND_CLOSE, "course_close.wav", SoundType.SOUND, false);
public void createResult(PlayerResource resource) {

loadSkin(SkinType.COURSE_RESULT);

Expand All @@ -60,7 +50,7 @@ public void create() {

updateScoreDatabase();

// リプレイの自動保存
// �꺁�깤�꺃�궎�겗�눎�땿岳앭춼
if(resource.getPlayMode() == PlayMode.PLAY){
for(int i=0;i<REPLAY_SIZE;i++){
if(MusicResult.ReplayAutoSaveConstraint.get(resource.getConfig().getAutoSaveReplay()[i]).isQualified(oldscore ,newscore)) {
Expand Down Expand Up @@ -191,7 +181,7 @@ public void updateScoreDatabase() {
}

if(send) {
Logger.getGlobal().info("IRへスコア送信中(未実装)");
Logger.getGlobal().info("IR�겦�궧�궠�궋�곦에訝�(�쑋若잒즳)");
main.switchTimer(TIMER_IR_CONNECT_BEGIN, true);
state = STATE_IR_PROCESSING;
final IRScoreData oldscore = score;
Expand All @@ -200,7 +190,7 @@ public void updateScoreDatabase() {
@Override
public void run() {
main.switchTimer(TIMER_IR_CONNECT_SUCCESS, true);
Logger.getGlobal().info("IRへスコア送信完了(未実装)");
Logger.getGlobal().info("IR�겦�궧�궠�궋�곦에若뚥틙(�쑋若잒즳)");
// ir.sendPlayData(resource.getBMSModel(), resource.getScoreData());
// IRResponse<IRScoreData[]> response = ir.getPlayData(null, resource.getBMSModel());
// if(response.isSuccessed()) {
Expand All @@ -219,10 +209,10 @@ public void run() {
// }
// }
// setTimerOn(TIMER_IR_CONNECT_SUCCESS, true);
// Logger.getGlobal().info("IRへスコア送信完了");
// Logger.getGlobal().info("IR�겦�궧�궠�궋�곦에若뚥틙");
// } else {
// setTimerOn(TIMER_IR_CONNECT_FAIL, true);
// Logger.getGlobal().warning("IRからのスコア取得失敗 : " + response.getMessage());
// Logger.getGlobal().warning("IR�걢�굢�겗�궧�궠�궋�룚孃쀥ㅁ�븮 : " + response.getMessage());
// }

state = STATE_IR_FINISHED;
Expand All @@ -238,29 +228,13 @@ public void run() {
play(SOUND_FAIL);
}

Logger.getGlobal().info("スコアデータベース更新完了 ");
Logger.getGlobal().info("�궧�궠�궋�깈�꺖�궭�깧�꺖�궧�쎍�뼭若뚥틙 ");
}

public int getJudgeCount(int judge, boolean fast) {
final PlayerResource resource = main.getPlayerResource();
IRScoreData score = resource.getCourseScoreData();
if (score != null) {
switch (judge) {
case 0:
return fast ? score.getEpg() : score.getLpg();
case 1:
return fast ? score.getEgr() : score.getLgr();
case 2:
return fast ? score.getEgd() : score.getLgd();
case 3:
return fast ? score.getEbd() : score.getLbd();
case 4:
return fast ? score.getEpr() : score.getLpr();
case 5:
return fast ? score.getEms() : score.getLms();
}
}
return 0;
return scoreJudge(score, judge, fast);
}

public String getTextValue(int id) {
Expand Down Expand Up @@ -337,11 +311,11 @@ public void dispose() {
super.dispose();
}

private void saveReplayData(int index) {
public void saveReplayData(int index) {
final PlayerResource resource = main.getPlayerResource();
if (resource.getPlayMode() == PlayMode.PLAY && resource.getCourseScoreData() != null) {
if (saveReplay[index] != ReplayStatus.SAVED && resource.isUpdateScore()) {
// 保存されているリプレイデータがない場合は、EASY以上で自動保存
// 岳앭춼�걬�굦�겍�걚�굥�꺁�깤�꺃�궎�깈�꺖�궭�걣�겒�걚�졃�릦�겘�갋ASY餓δ툓�겎�눎�땿岳앭춼
ReplayData[] rd = resource.getCourseReplay();
for(int i = 0; i < rd.length; i++) {
rd[i].gauge = resource.getPlayerConfig().getGauge();
Expand Down Expand Up @@ -397,19 +371,6 @@ public int getImageIndex(int id) {
}

public void executeClickEvent(int id, int arg) {
switch (id) {
case BUTTON_REPLAY:
saveReplayData(0);
break;
case BUTTON_REPLAY2:
saveReplayData(1);
break;
case BUTTON_REPLAY3:
saveReplayData(2);
break;
case BUTTON_REPLAY4:
saveReplayData(3);
break;
}
ClickResult(id);
}
}
20 changes: 9 additions & 11 deletions src/bms/player/beatoraja/result/CourseResultSkin.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package bms.player.beatoraja.result;

import bms.player.beatoraja.Resolution;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import bms.player.beatoraja.skin.Skin;

import bms.player.beatoraja.MainState;
import bms.player.beatoraja.skin.*;

import static bms.player.beatoraja.skin.SkinProperty.*;

/**
* �꺁�궢�꺂�깉�궧�궘�꺍1
*/
public class CourseResultSkin extends Skin {

private int ranktime;

int ranktime;


public CourseResultSkin(Resolution src, Resolution dst) {
super(src, dst);
Expand All @@ -26,5 +23,6 @@ public int getRankTime() {
public void setRankTime(int ranktime) {
this.ranktime = ranktime;
}

}

82 changes: 23 additions & 59 deletions src/bms/player/beatoraja/result/MusicResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import bms.player.beatoraja.skin.SkinType;

/**
* リザルト
* �꺁�궣�꺂�깉
*
* @author exch
*/
Expand All @@ -31,17 +31,17 @@ public class MusicResult extends AbstractResult {
private IRScoreData oldscore = new IRScoreData();

/**
* 全ノーツの平均ズレ
* �뀲�깕�꺖�깂�겗亮녑쓦�궨�꺃
*/
private float avgduration;

/**
* タイミング分布
* �궭�궎�깱�꺍�궛�늽躍�123
*/
private TimingDistribution timingDistribution;

/**
* タイミング分布レンジ
* �궭�궎�깱�꺍�궛�늽躍껁꺃�꺍�궦
*/
final int distRange = 150;

Expand All @@ -53,24 +53,16 @@ public MusicResult(MainController main) {
timingDistribution = new TimingDistribution(distRange);
}

public void create() {
final PlayerResource resource = main.getPlayerResource();
for(int i = 0;i < REPLAY_SIZE;i++) {
saveReplay[i] = main.getPlayDataAccessor().existsReplayData(resource.getBMSModel(),
resource.getPlayerConfig().getLnmode(), i) ? ReplayStatus.EXIST : ReplayStatus.NOT_EXIST ;
}

setSound(SOUND_CLEAR, "clear.wav", SoundType.SOUND, false);
setSound(SOUND_FAIL, "fail.wav", SoundType.SOUND, false);
setSound(SOUND_CLOSE, "resultclose.wav", SoundType.SOUND, false);
public void createResult(PlayerResource resource) {

property = ResultKeyProperty.get(resource.getBMSModel().getMode());
if (property == null) {
property = ResultKeyProperty.BEAT_7K;
}

updateScoreDatabase();
// リプレイの自動保存
// �꺁�깤�꺃�궎�겗�눎�땿岳앭춼
if (resource.getPlayMode() == PlayMode.PLAY) {
for (int i = 0; i < REPLAY_SIZE; i++) {
if (ReplayAutoSaveConstraint.get(resource.getConfig().getAutoSaveReplay()[i]).isQualified(oldscore,
Expand All @@ -79,7 +71,7 @@ public void create() {
}
}
}
// コースモードの場合はリプレイデータをストックする
// �궠�꺖�궧�깴�꺖�깋�겗�졃�릦�겘�꺁�깤�꺃�궎�깈�꺖�궭�굮�궧�깉�긿�궚�걲�굥
if (resource.getCourseBMSModels() != null) {
resource.addCourseReplay(resource.getReplayData());
resource.addCourseGauge(resource.getGauge());
Expand Down Expand Up @@ -116,7 +108,7 @@ public void render() {
if (resource.getGauge()[resource.getGrooveGauge().getType()]
.get(resource.getGauge()[resource.getGrooveGauge().getType()].size - 1) <= 0) {
if (resource.getCourseScoreData() != null) {
// 未達曲のノーツをPOORとして加算
// �쑋�걫�쎊�겗�깕�꺖�깂�굮POOR�겏�걮�겍�뒥嶸�
final List<FloatArray[]> coursegauge = resource.getCourseGauge();
final int cg = resource.getCourseBMSModels().length;
for (int i = 0; i < cg; i++) {
Expand All @@ -125,16 +117,16 @@ public void render() {
+ resource.getCourseBMSModels()[i].getTotalNotes());
}
}
// 不合格リザルト
// 訝띶릦�졏�꺁�궣�꺂�깉
main.changeState(MainController.STATE_GRADE_RESULT);
} else {
// コーススコアがない場合は選曲画面へ
// �궠�꺖�궧�궧�궠�궋�걣�겒�걚�졃�릦�겘�겦�쎊�뵽�씊�겦
main.changeState(MainController.STATE_SELECTMUSIC);
}
} else if (resource.nextCourse()) {
main.changeState(MainController.STATE_PLAYBMS);
} else {
// 合格リザルト
// �릦�졏�꺁�궣�꺂�깉
if (resource.getPlayerConfig().isContinueUntilEndOfSong()) {
int changedGaugeType = resource.getGrooveGauge()
.changeTypeOfClear(resource.getGrooveGauge().getType());
Expand All @@ -159,15 +151,15 @@ public void render() {
}
if (resource.getPlayMode() == PlayMode.PLAY
&& key == ResultKeyProperty.ResultKey.REPLAY_DIFFERENT) {
Logger.getGlobal().info("オプションを変更せずリプレイ");
// オプションを変更せず同じ譜面でリプレイ
Logger.getGlobal().info("�궕�깤�궥�깾�꺍�굮鸚됪쎍�걵�걳�꺁�깤�꺃�궎");
// �궕�깤�궥�깾�꺍�굮鸚됪쎍�걵�걳�릪�걯鈺쒒씊�겎�꺁�깤�꺃�궎
resource.getReplayData().pattern = null;
resource.reloadBMSFile();
main.changeState(MainController.STATE_PLAYBMS);
} else if (resource.getPlayMode() == PlayMode.PLAY
&& key == ResultKeyProperty.ResultKey.REPLAY_SAME) {
// 同じ譜面でリプレイ
Logger.getGlobal().info("同じ譜面でリプレイ");
// �릪�걯鈺쒒씊�겎�꺁�깤�꺃�궎
Logger.getGlobal().info("�릪�걯鈺쒒씊�겎�꺁�깤�꺃�궎");
resource.reloadBMSFile();
main.changeState(MainController.STATE_PLAYBMS);
} else {
Expand Down Expand Up @@ -303,7 +295,7 @@ private void updateScoreDatabase() {
avgduration /= count;
timingDistribution.statisticValueCalcuate();

// コースモードの場合はコーススコアに加算・累積する
// �궠�꺖�궧�깴�꺖�깋�겗�졃�릦�겘�궠�꺖�궧�궧�궠�궋�겓�뒥嶸쀣꺕榮�令띲걲�굥
if (resource.getCourseBMSModels() != null) {
if (resource.getScoreData().getClear() == Failed.id) {
resource.getScoreData().setClear(NoPlay.id);
Expand Down Expand Up @@ -364,7 +356,7 @@ private void updateScoreDatabase() {
cscore.setClear(Failed.id);

boolean b = false;
// 残りの曲がある場合はtotalnotesをBPに加算する
// 餘뗣굤�겗�쎊�걣�걗�굥�졃�릦�겘totalnotes�굮BP�겓�뒥嶸쀣걲�굥1
for (BMSModel m : resource.getCourseBMSModels()) {
if (b) {
cscore.setMinbp(cscore.getMinbp() + m.getTotalNotes());
Expand All @@ -380,7 +372,7 @@ private void updateScoreDatabase() {
if (resource.getPlayMode() == PlayMode.PLAY) {
main.getPlayDataAccessor().writeScoreDara(resource.getScoreData(), resource.getBMSModel(),
resource.getPlayerConfig().getLnmode(), resource.isUpdateScore());
// TODO スコアハッシュがあり、有効期限が切れていないものを送信する?
// TODO �궧�궠�궋�깗�긿�궥�깷�걣�걗�굤�곫쐣�듅�쐿�솏�걣�늾�굦�겍�걚�겒�걚�굚�겗�굮�곦에�걲�굥竊�
IRConnection ir = main.getIRConnection();
if (ir != null) {
boolean send = resource.isUpdateScore();
Expand All @@ -399,7 +391,7 @@ private void updateScoreDatabase() {
}

if(send) {
Logger.getGlobal().info("IRへスコア送信中");
Logger.getGlobal().info("IR�겦�궧�궠�궋�곦에訝�");
main.switchTimer(TIMER_IR_CONNECT_BEGIN, true);
state = STATE_IR_PROCESSING;
Thread irprocess = new Thread() {
Expand All @@ -424,10 +416,10 @@ public void run() {
}
}
main.switchTimer(TIMER_IR_CONNECT_SUCCESS, true);
Logger.getGlobal().info("IRへスコア送信完了");
Logger.getGlobal().info("IR�겦�궧�궠�궋�곦에若뚥틙");
} else {
main.switchTimer(TIMER_IR_CONNECT_FAIL, true);
Logger.getGlobal().warning("IRからのスコア取得失敗 : " + response.getMessage());
Logger.getGlobal().warning("IR�걢�굢�겗�궧�궠�궋�룚孃쀥ㅁ�븮 : " + response.getMessage());
}

state = STATE_IR_FINISHED;
Expand All @@ -447,23 +439,7 @@ public void run() {

public int getJudgeCount(int judge, boolean fast) {
IRScoreData score = main.getPlayerResource().getScoreData();
if (score != null) {
switch (judge) {
case 0:
return fast ? score.getEpg() : score.getLpg();
case 1:
return fast ? score.getEgr() : score.getLgr();
case 2:
return fast ? score.getEgd() : score.getLgd();
case 3:
return fast ? score.getEbd() : score.getLbd();
case 4:
return fast ? score.getEpr() : score.getLpr();
case 5:
return fast ? score.getEms() : score.getLms();
}
}
return 0;
return scoreJudge(score, judge, fast);
}

@Override
Expand Down Expand Up @@ -620,19 +596,7 @@ public boolean getBooleanValue(int id) {
return super.getBooleanValue(id);
}

public int getImageIndex(int id) {
switch (id) {
case NUMBER_CLEAR:
final PlayerResource resource = main.getPlayerResource();
if (resource.getScoreData() != null) {
return resource.getScoreData().getClear();
}
return Integer.MIN_VALUE;
case NUMBER_TARGET_CLEAR:
return oldscore.getClear();
}
return super.getImageIndex(id);
}


public void executeClickEvent(int id, int arg) {
switch (id) {
Expand Down
Loading

0 comments on commit a4ed48a

Please sign in to comment.