-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,183 additions
and
624 deletions.
There are no files selected for viewing
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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
src/main/java/com/faforever/api/map/MapLuaAccessor.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,104 @@ | ||
package com.faforever.api.map; | ||
|
||
import com.faforever.commons.lua.LuaAccessor; | ||
import org.luaj.vm2.LuaValue; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import java.util.OptionalInt; | ||
|
||
public class MapLuaAccessor { | ||
private static final String ROOT_ELEMENT = "ScenarioInfo"; | ||
private static final String CONFIGURATIONS = "Configurations"; | ||
private static final String NAME = "name"; | ||
private static final String DESCRIPTION = "description"; | ||
private static final String TYPE = "type"; | ||
private static final String SIZE = "size"; | ||
private static final String MAP_VERSION = "map_version"; | ||
private static final String CONFIGURATION_STANDARD = "standard"; | ||
private static final String CONFIGURATION_STANDARD_TEAMS = "teams"; | ||
private static final String CONFIGURATION_STANDARD_TEAMS_NAME = "name"; | ||
private static final String CONFIGURATION_STANDARD_TEAMS_ARMIES = "armies"; | ||
|
||
|
||
private final LuaAccessor luaAccessor; | ||
|
||
private MapLuaAccessor(LuaAccessor luaAccessor) { | ||
this.luaAccessor = luaAccessor; | ||
} | ||
|
||
public static MapLuaAccessor of(Path scenarioLuaPath) throws IOException { | ||
return new MapLuaAccessor(LuaAccessor.of(scenarioLuaPath, ROOT_ELEMENT)); | ||
} | ||
|
||
public static MapLuaAccessor of(String scenarioLuaCode) throws IOException { | ||
return new MapLuaAccessor(LuaAccessor.of(scenarioLuaCode, ROOT_ELEMENT)); | ||
} | ||
|
||
public Optional<String> getName() { | ||
return luaAccessor.readVariableString(NAME); | ||
} | ||
|
||
public Optional<String> getDescription() { | ||
return luaAccessor.readVariableString(DESCRIPTION); | ||
} | ||
|
||
public Optional<String> getType() { | ||
return luaAccessor.readVariableString(TYPE); | ||
} | ||
|
||
public Optional<LuaValue> getSize() { | ||
return luaAccessor.readVariable(SIZE); | ||
} | ||
|
||
public OptionalInt getMapVersion() { | ||
return luaAccessor.readVariableInt(MAP_VERSION); | ||
} | ||
|
||
public boolean hasVariableMatching(String regex, String... names) { | ||
return luaAccessor.hasVariableMatching(regex, names); | ||
} | ||
|
||
public Optional<LuaValue> getFirstTeam() { | ||
Optional<LuaValue> configurationStandardTeamsOptional = luaAccessor.readVariable( | ||
CONFIGURATIONS, CONFIGURATION_STANDARD, CONFIGURATION_STANDARD_TEAMS); | ||
|
||
return configurationStandardTeamsOptional | ||
.map(teams -> teams.get(1)); | ||
} | ||
|
||
public boolean hasInvalidTeam() { | ||
return getFirstTeam() | ||
.map(firstTeam -> | ||
!LuaAccessor.isValue(firstTeam, CONFIGURATION_STANDARD_TEAMS_NAME) || | ||
!LuaAccessor.isValue(firstTeam, CONFIGURATION_STANDARD_TEAMS_ARMIES) || | ||
!firstTeam.get(CONFIGURATION_STANDARD_TEAMS_NAME).tojstring().equals("FFA")) | ||
.orElse(true); | ||
} | ||
|
||
public String getName$() { | ||
return getName().get(); | ||
} | ||
|
||
public String getDescription$() { | ||
return getDescription().get(); | ||
} | ||
|
||
public String getType$() { | ||
return getType().get(); | ||
} | ||
|
||
public LuaValue getSize$() { | ||
return getSize().get(); | ||
} | ||
|
||
public int getMapVersion$() { | ||
return getMapVersion().getAsInt(); | ||
} | ||
|
||
public LuaValue getFirstTeam$() { | ||
return getFirstTeam().get(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/faforever/api/map/MapNameValidationResponse.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,22 @@ | ||
package com.faforever.api.map; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
@Value | ||
@Builder | ||
public class MapNameValidationResponse { | ||
String displayName; | ||
int nextVersion; | ||
String folderName; | ||
FileNames fileNames; | ||
|
||
@Value | ||
@Builder | ||
static class FileNames { | ||
String scmap; | ||
String saveLua; | ||
String scenarioLua; | ||
String scriptLua; | ||
} | ||
} |
Oops, something went wrong.