Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial cleanup, introduced Action interface.
- Loading branch information
Showing
12 changed files
with
758 additions
and
753 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
cardshifter-core/src/main/java/com/cardshifter/core/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
package com.cardshifter.core; | ||
|
||
/** | ||
* | ||
* @author Frank van Heeswijk | ||
*/ | ||
public interface Action { | ||
boolean isAllowed(); | ||
|
||
void perform(); | ||
} |
69 changes: 34 additions & 35 deletions
69
cardshifter-core/src/main/java/com/cardshifter/core/CardAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
package com.cardshifter.core; | ||
|
||
import java.util.Objects; | ||
|
||
import org.luaj.vm2.LuaValue; | ||
import org.luaj.vm2.lib.jse.CoerceJavaToLua; | ||
|
||
public class CardAction extends UsableAction { | ||
|
||
private final Card card; | ||
|
||
public CardAction(final Card card, final String name, final LuaValue allowedFunction, final LuaValue actionFunction) { | ||
super(name, allowedFunction, actionFunction); | ||
this.card = Objects.requireNonNull(card, "card"); | ||
} | ||
|
||
public Card getCard() { | ||
return card; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{Action " + getName() + " on card " + card + "}"; | ||
} | ||
|
||
@Override | ||
protected LuaValue methodArg() { | ||
return CoerceJavaToLua.coerce(card); | ||
} | ||
|
||
@Override | ||
protected Game getGame() { | ||
return card.getGame(); | ||
} | ||
} | ||
package com.cardshifter.core; | ||
|
||
import java.util.Objects; | ||
|
||
import org.luaj.vm2.LuaValue; | ||
import org.luaj.vm2.lib.jse.CoerceJavaToLua; | ||
|
||
public class CardAction extends UsableAction { | ||
private final Card card; | ||
|
||
public CardAction(final Card card, final String name, final LuaValue allowedFunction, final LuaValue actionFunction) { | ||
super(name, allowedFunction, actionFunction); | ||
this.card = Objects.requireNonNull(card, "card"); | ||
} | ||
|
||
public Card getCard() { | ||
return card; | ||
} | ||
|
||
@Override | ||
protected LuaValue methodArg() { | ||
return CoerceJavaToLua.coerce(card); | ||
} | ||
|
||
@Override | ||
protected Game getGame() { | ||
return card.getGame(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{Action " + getName() + " on card " + card + "}"; | ||
} | ||
} |
44 changes: 21 additions & 23 deletions
44
cardshifter-core/src/main/java/com/cardshifter/core/CommandLineOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
package com.cardshifter.core; | ||
|
||
import java.util.Random; | ||
|
||
import com.beust.jcommander.Parameter; | ||
|
||
public class CommandLineOptions { | ||
|
||
@Parameter(names = { "--file", "-f" }, description = "Script file to run") | ||
private String script; | ||
|
||
@Parameter(names = { "--seed", "-s" }, description = "Set random seed") | ||
private Integer seed; | ||
|
||
public Random getRandom() { | ||
return seed == null ? new Random() : new Random(seed); | ||
} | ||
|
||
public String getScript() { | ||
return script; | ||
} | ||
|
||
} | ||
package com.cardshifter.core; | ||
|
||
import java.util.Random; | ||
|
||
import com.beust.jcommander.Parameter; | ||
|
||
public class CommandLineOptions { | ||
@Parameter(names = { "--file", "-f" }, description = "Script file to run") | ||
private String script; | ||
|
||
@Parameter(names = { "--seed", "-s" }, description = "Set random seed") | ||
private Integer seed; | ||
|
||
public Random getRandom() { | ||
return (seed == null) ? new Random() : new Random(seed); | ||
} | ||
|
||
public String getScript() { | ||
return script; | ||
} | ||
} |
Oops, something went wrong.