Skip to content

Commit

Permalink
Merge pull request #717 from frank-weinberg/feature/copy-games
Browse files Browse the repository at this point in the history
add copy button for games
  • Loading branch information
frank-weinberg authored Jun 28, 2024
2 parents 51156c9 + f33cc5a commit 5ebb1bd
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 8 deletions.
1 change: 1 addition & 0 deletions html/settings/sb_data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<button class="Delete Left" sbCall="datDeleteElem">Delete</button>
<a download class="Download Left" sbAttr="href: Name: datGameDlLink" sbButton>Download</a>
<a class="Edit Left" sbAttr="href: -: '/nso/hnso?game=' + k.Game" sbButton>Edit</a>
<button class="Copy Left" sbSet="Copy">Copy</button>
<span class="Name" sbDisplay="Name"></span>
</td>
</tr>
Expand Down
34 changes: 28 additions & 6 deletions src/com/carolinarollergirls/scoreboard/core/game/GameImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.carolinarollergirls.scoreboard.core.interfaces.Jam;
import com.carolinarollergirls.scoreboard.core.interfaces.Media.MediaFile;
import com.carolinarollergirls.scoreboard.core.interfaces.Media.MediaType;
import com.carolinarollergirls.scoreboard.core.interfaces.Official;
import com.carolinarollergirls.scoreboard.core.interfaces.Penalty;
import com.carolinarollergirls.scoreboard.core.interfaces.Period;
import com.carolinarollergirls.scoreboard.core.interfaces.Period.PeriodSnapshot;
Expand Down Expand Up @@ -58,18 +59,33 @@
public class GameImpl extends ScoreBoardEventProviderImpl<Game> implements Game {
public GameImpl(ScoreBoard sb, PreparedTeam team1, PreparedTeam team2, Ruleset rs) {
super(sb, UUID.randomUUID().toString(), ScoreBoard.GAME);
initReferences(rs);
initReferences(rs, null);
getTeam(Team.ID_1).loadPreparedTeam(team1);
getTeam(Team.ID_2).loadPreparedTeam(team2);
jsonSnapshotter = new JSONStateSnapshotter(sb.getJsm(), this);
}
public GameImpl(ScoreBoard parent, String id) {
super(parent, id, ScoreBoard.GAME);
initReferences(scoreBoard.getRulesets().getRuleset(Rulesets.ROOT_ID));
initReferences(scoreBoard.getRulesets().getRuleset(Rulesets.ROOT_ID), null);
jsonSnapshotter = new JSONStateSnapshotter(getScoreBoard().getJsm(), this);
}
public GameImpl(Game source) {
super(source.getScoreBoard(), UUID.randomUUID().toString(), ScoreBoard.GAME);
initReferences(source.getRuleset(), source);
set(NAME_FORMAT, source.get(NAME_FORMAT));
for (ValWithId ei : source.getAll(EVENT_INFO)) { add(EVENT_INFO, ei); }
for (Official nso : source.getAll(NSO)) { add(NSO, new OfficialImpl(this, nso)); }
for (Official so : source.getAll(REF)) { add(REF, new OfficialImpl(this, so)); }
Official hnso = source.get(HEAD_NSO);
if (hnso != null) {
String hnsoName = hnso.get(Official.NAME);
for (Official nso : getAll(NSO)) {
if (nso.get(Official.NAME) == hnsoName) { set(HEAD_NSO, nso); }
}
}
}

private void initReferences(Ruleset rs) {
private void initReferences(Ruleset rs, Game source) {
addProperties(props);

setCopy(CURRENT_PERIOD_NUMBER, this, CURRENT_PERIOD, Period.NUMBER, true);
Expand All @@ -81,8 +97,11 @@ private void initReferences(Ruleset rs) {
setCopy(OFFICIAL_REVIEW, this, CURRENT_TIMEOUT, Timeout.REVIEW, false);
setCopy(RULESET_NAME, this, RULESET, Ruleset.NAME, true);
setRuleset(rs);
add(TEAM, new TeamImpl(this, Team.ID_1));
add(TEAM, new TeamImpl(this, Team.ID_2));
if (rs == null) {
for (Rule r : Rule.values()) { set(r, source.get(r)); }
}
add(TEAM, source != null ? new TeamImpl(this, source.getTeam(Team.ID_1)) : new TeamImpl(this, Team.ID_1));
add(TEAM, source != null ? new TeamImpl(this, source.getTeam(Team.ID_2)) : new TeamImpl(this, Team.ID_2));
addWriteProtection(TEAM);
add(CLOCK, new ClockImpl(this, Clock.ID_PERIOD));
add(CLOCK, new ClockImpl(this, Clock.ID_JAM));
Expand Down Expand Up @@ -469,6 +488,8 @@ public void execute(Command prop, Source source) {
add(Team.BOX_TRIP, new BoxTripImpl(this));
} else if (prop == START_JAMMER_BOX_TRIP) {
jammerBoxEntry();
} else if (prop == COPY) {
parent.add(ownType, new GameImpl(this));
}
}

Expand All @@ -480,7 +501,8 @@ public ScoreBoardEventProvider create(Child<? extends ScoreBoardEventProvider> p
if (prop == Period.JAM) {
int num = Integer.parseInt(id);
if (source.isFile()) {
return new JamImpl(this, num);
getUpcomingJam().set(Jam.NUMBER, num, Source.RENUMBER);
return getUpcomingJam();
} else if (num == getCurrentPeriod().getCurrentJamNumber()) {
// could be a race around jam start
return getCurrentPeriod().getCurrentJam();
Expand Down
16 changes: 16 additions & 0 deletions src/com/carolinarollergirls/scoreboard/core/game/OfficialImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.carolinarollergirls.scoreboard.core.game;

import java.util.UUID;

import com.carolinarollergirls.scoreboard.core.interfaces.Game;
import com.carolinarollergirls.scoreboard.core.interfaces.Official;
import com.carolinarollergirls.scoreboard.core.interfaces.Team;
Expand All @@ -13,6 +15,15 @@ public OfficialImpl(Game g, String id, Child<Official> type) {
game = g;
addProperties(props);
}
public OfficialImpl(Game g, Official source) {
this(g, UUID.randomUUID().toString(), source.getType());
set(ROLE, source.get(ROLE));
set(NAME, source.get(NAME));
set(LEAGUE, source.get(LEAGUE));
set(CERT, source.get(CERT));
if (source.get(P1_TEAM) != null) { set(P1_TEAM, g.getTeam(source.get(P1_TEAM).getProviderId())); }
set(SWAP, source.get(SWAP));
}

@Override
public int compareTo(Official other) {
Expand Down Expand Up @@ -83,5 +94,10 @@ private int roleIndex() {
}
}

@Override
public Child<Official> getType() {
return ownType;
}

private Game game;
}
11 changes: 11 additions & 0 deletions src/com/carolinarollergirls/scoreboard/core/game/SkaterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ public SkaterImpl(Team t, PreparedSkater ps, String i) {
set(PREPARED_SKATER, ps);
setFlags(ps.get(FLAGS));
}
public SkaterImpl(Team t, Skater source) {
this(t, (String) null);
PreparedSkater ps = source.get(PREPARED_SKATER);
set(PREPARED_SKATER, ps);
if (ps == null || !team.get(Team.PREPARED_TEAM_CONNECTED)) {
set(NAME, source.get(NAME));
set(ROSTER_NUMBER, source.get(NAME));
set(PRONOUNS, source.get(NAME));
}
set(FLAGS, source.get(FLAGS));
}

private void initialize() {
addProperties(props);
Expand Down
20 changes: 18 additions & 2 deletions src/com/carolinarollergirls/scoreboard/core/game/TeamImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ public TeamImpl(Game g, String i) {
.addSource(getPosition(FloorPosition.BLOCKER3), Position.SKATER);
providers.put(skaterListener, null);
}
public TeamImpl(Game g, Team source) {
this(g, source.getProviderId());
set(PREPARED_TEAM_CONNECTED, source.get(PREPARED_TEAM_CONNECTED));
set(PREPARED_TEAM, source.get(PREPARED_TEAM));
set(UNIFORM_COLOR, source.get(UNIFORM_COLOR));
if (!get(PREPARED_TEAM_CONNECTED)) {
set(LEAGUE_NAME, source.get(LEAGUE_NAME));
set(TEAM_NAME, source.get(TEAM_NAME));
set(LOGO, source.get(LOGO));
}
for (ValWithId an : source.getAll(ALTERNATE_NAME)) { add(ALTERNATE_NAME, an); }
for (ValWithId c : source.getAll(COLOR)) { add(COLOR, c); }
for (Skater s : source.getAll(SKATER)) { add(SKATER, new SkaterImpl(this, s)); }
}

@Override
public String getProviderId() {
Expand Down Expand Up @@ -484,8 +498,10 @@ public void setLogo(String l) {
@Override
public void loadPreparedTeam(PreparedTeam pt) {
synchronized (coreLock) {
set(PREPARED_TEAM_CONNECTED, pt != null, Flag.SPECIAL_CASE);
set(PREPARED_TEAM, pt);
if (pt != null) {
set(PREPARED_TEAM_CONNECTED, pt != null, Flag.SPECIAL_CASE);
set(PREPARED_TEAM, pt);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public static State fromString(String s) {
public static final Command EXPORT = new Command("Export", props);
public static final Command START_BOX_TRIP = new Command("StartBoxTrip", props);
public static final Command START_JAMMER_BOX_TRIP = new Command("StartJammerBoxTrip", props);
public static final Command COPY = new Command("Copy", props);

public static final String SETTING_DEFAULT_NAME_FORMAT = "ScoreBoard.Game.DefaultNameFormat";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import java.util.ArrayList;
import java.util.Collection;

import com.carolinarollergirls.scoreboard.event.Child;
import com.carolinarollergirls.scoreboard.event.Property;
import com.carolinarollergirls.scoreboard.event.ScoreBoardEventProvider;
import com.carolinarollergirls.scoreboard.event.Value;

public interface Official extends ScoreBoardEventProvider {
public int compareTo(Official other);

public Child<Official> getType();

public static Collection<Property<?>> props = new ArrayList<>();

public static final Value<String> ROLE = new Value<>(String.class, "Role", "", props);
Expand Down

0 comments on commit 5ebb1bd

Please sign in to comment.