Comments (4)
A lot of the code here is indeed duplicated but there may be subtle differences. I believe the initial implementation of the single player server was an experiment and we had just copy-pasted the code but would make sense to convert into a shared library.
from duelyst.
I wrote a Python script to diff these automatically:
from typing import Dict, List
# Identifies CoffeeScript functions through signature and indentation.
def find_functions(filename: str) -> Dict[str, List[str]]:
start_index = -1
functions: Dict[str, List[str]] = dict()
with open(filename, 'r') as f:
lines = f.readlines()
for i in range(0, len(lines)):
line = lines[i]
# Ignore comments and lines starting with whitespace.
if line[0] in ('#', '\t', ' '): continue
# Save the starting line for function declarations.
if '->' in line and ' = (' in line:
start_index = i
continue
# Don't try to find the end of a function before one begins.
if start_index == -1: continue
# Something new has started at the top level; save and reset.
functions[lines[start_index].rstrip('\n')] = lines[start_index:i]
start_index = -1
return functions
# Returns True if the provided lists have identical contents.
def diff_function(a: List[str], b: List[str]) -> bool:
if len(a) != len(b):
return False
for i in range(len(a)):
if a[i] != b[i]:
return False
return True
if __name__ == '__main__':
game = find_functions('game.coffee')
sp = find_functions('single_player.coffee')
for f in game.keys() & sp.keys():
if diff_function(game[f], sp[f]):
print('Function with declaration {} is duplicated!'.format(f))
The results are:
Function with declaration afterGameOver = (gameId, gameSession, mouseAndUIEvents) -> is duplicated!
Function with declaration destroyGameSessionIfNoConnectionsLeft = (gameId,persist=false)-> is duplicated!
Function with declaration dnsHealthCheck = () -> is duplicated!
Function with declaration flushSpectatorNetworkEventBuffer = (gameId) -> is duplicated!
Function with declaration getConnectedSpectatorsDataForGamePlayer = (gameId,playerId)-> is duplicated!
Function with declaration initGameSession = (gameId,onComplete) -> is duplicated!
Function with declaration initSpectatorGameSession = (gameId)-> is duplicated!
Function with declaration onGameEvent = (eventData) -> is duplicated!
Function with declaration onGamePlayerJoin = (requestData) -> is duplicated!
Function with declaration onGameSpectatorJoin = (requestData) -> is duplicated!
Function with declaration onGameTimeTick = (gameId) -> is duplicated!
Function with declaration onInvalidAction = (event) -> is duplicated!
Function with declaration onSpectatorDelayedGameTick = (gameId) -> is duplicated!
Function with declaration onStep = (event) -> is duplicated!
Function with declaration playerLeaveGameIfNeeded = (socket, silent=false) -> is duplicated!
Function with declaration restartSpectatorDelayedGameInterval = (gameId) -> is duplicated!
Function with declaration restartTurnTimer = (gameId) -> is duplicated!
Function with declaration saveGameCount = (gameCount) -> is duplicated!
Function with declaration savePlayerCount = (playerCount) -> is duplicated!
Function with declaration shutdown = () -> is duplicated!
Function with declaration spectatorLeaveGameIfNeeded = (socket) -> is duplicated!
Function with declaration stopSpectatorDelayedGameInterval = (gameId) -> is duplicated!
Function with declaration stopTurnTimer = (gameId) -> is duplicated!
Function with declaration tearDownSpectateSystemsIfNoSpectatorsLeft = (gameId)-> is duplicated!
from duelyst.
Definitely! I'll diff each of these one at a time and see what we can do.
from duelyst.
Another challenge is the reliance on global vars, specifically these two:
io
object: https://github.com/open-duelyst/duelyst/blob/fa4184f/server/single_player.coffee#L73games
object: https://github.com/open-duelyst/duelyst/blob/fa4184f/server/single_player.coffee#L95
Functions accessing these (nearly all of the above) would need to be refactored or remain duplicated.
I made some progress on this work here: willroberts/duelyst@main...willroberts:duelyst:server-dedupe
Given the io
/games
access challenges I'll hold off on this for now.
from duelyst.
Related Issues (20)
- [P0] Missing WebGL hardware acceleration on some Linux systems e.g. Steam Deck HOT 11
- Purgatos doesn't seem to trigger. HOT 4
- it does not run: Looks like your video card is not supported. HOT 3
- [P3] Replace Moment.js with Day.js HOT 1
- [P0] Importing a decklist doesnt delete your previous deck/general. Many bugs happen as a result. HOT 2
- [P2] Cannot read property 'availableAt' of undefined HOT 4
- [P2] Bots can have partial or empty decks in practice mode HOT 2
- [P2] Missing cards after deck import HOT 5
- [P2] Github link opens Github in fullscreen with no way back to the game HOT 2
- [P0] Game interferes with Steam Deck overlay menus and keyboard
- You can build a Deck with less than 40 cards, circumventing deckbuilding restrictions HOT 2
- Error in current boss battle: cannot read properties of undefined - reading getIsFollowup HOT 1
- Please ignore HOT 1
- Seek bar/slider for watching replays
- Brazilian Portuguese Localization (pt-BR)
- Enable completely offline Duelyst development via Firebase Emulator instrumentation HOT 1
- tronpy.exceptions.TransactionError: Transaction expired HOT 2
- [P1] Invalid launch template in Terraform when not using custom AMI
- [P3] Fix consistency of AWS environment variables
- Game gifs - hero & map - does not render if the screen size is too small
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from duelyst.