Chore: code cleaning
This commit is contained in:
		| @@ -99,11 +99,6 @@ func fillCardMarks(ctx context.Context, room *models.Room) error { | |||||||
| 				room.Cards[i].Marks = append(room.Cards[i].Marks, mark) | 				room.Cards[i].Marks = append(room.Cards[i].Marks, mark) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		// marks, err := repo.CardMarksByCardID(ctx, card.ID) |  | ||||||
| 		// if err != nil { |  | ||||||
| 		// 	return err |  | ||||||
| 		// } |  | ||||||
| 		// room.Cards[i].Marks = marks |  | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| @@ -117,18 +112,6 @@ func getPlayerByCtx(ctx context.Context) (*models.Player, error) { | |||||||
| 	return repo.PlayerGetByName(ctx, username) | 	return repo.PlayerGetByName(ctx, username) | ||||||
| } | } | ||||||
|  |  | ||||||
| // // DEPRECATED |  | ||||||
| // func leaveRole(fi *models.FullInfo) { |  | ||||||
| // 	fi.Room.RedTeam.Guessers = utils.RemoveFromSlice(fi.State.Username, fi.Room.RedTeam.Guessers) |  | ||||||
| // 	fi.Room.BlueTeam.Guessers = utils.RemoveFromSlice(fi.State.Username, fi.Room.BlueTeam.Guessers) |  | ||||||
| // 	if fi.Room.RedTeam.Mime == fi.State.Username { |  | ||||||
| // 		fi.Room.RedTeam.Mime = "" |  | ||||||
| // 	} |  | ||||||
| // 	if fi.Room.BlueTeam.Mime == fi.State.Username { |  | ||||||
| // 		fi.Room.BlueTeam.Mime = "" |  | ||||||
| // 	} |  | ||||||
| // } |  | ||||||
|  |  | ||||||
| func joinTeam(ctx context.Context, role, team string) (*models.FullInfo, error) { | func joinTeam(ctx context.Context, role, team string) (*models.FullInfo, error) { | ||||||
| 	// get username | 	// get username | ||||||
| 	fi, _ := getFullInfoByCtx(ctx) | 	fi, _ := getFullInfoByCtx(ctx) | ||||||
| @@ -219,10 +202,6 @@ func loadCards(room *models.Room) { | |||||||
| 		fmt.Println("failed to load cards", "error", err) | 		fmt.Println("failed to load cards", "error", err) | ||||||
| 	} | 	} | ||||||
| 	room.Cards = cards | 	room.Cards = cards | ||||||
| 	// room.WCMap = make(map[string]models.WordColor) |  | ||||||
| 	// for _, card := range room.Cards { |  | ||||||
| 	// 	room.WCMap[card.Word] = card.Color |  | ||||||
| 	// } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func recoverBots() { | func recoverBots() { | ||||||
| @@ -250,35 +229,6 @@ func recoverBot(bm models.Player) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // func recoverPlayers() { |  | ||||||
| // 	players := listPlayers() |  | ||||||
| // 	for playerName, playerMap := range players { |  | ||||||
| // 		if err := recoverPlayer(playerMap); err != nil { |  | ||||||
| // 			log.Warn("failed to recover player", "playerName", playerName, "error", err) |  | ||||||
| // 		} |  | ||||||
| // 	} |  | ||||||
| // } |  | ||||||
|  |  | ||||||
| // func recoverPlayer(pm map[string]string) error { |  | ||||||
| // 	// check if room still exists |  | ||||||
| // 	room, err := repo.RoomGetByID(context.Background(), pm["RoomID"]) |  | ||||||
| // 	if err != nil { |  | ||||||
| // 		return fmt.Errorf("no such room: %s; err: %w", pm["RoomID"], err) |  | ||||||
| // 	} |  | ||||||
| // 	log.Debug("recovering player", "player", pm) |  | ||||||
| // 	role, team, ok := room.GetPlayerByName(pm["Username"]) |  | ||||||
| // 	if !ok { |  | ||||||
| // 		return fmt.Errorf("failed to find player %s in the room %v", pm["Username"], room) |  | ||||||
| // 	} |  | ||||||
| // 	us := &models.Player{ |  | ||||||
| // 		Username: pm["Username"], |  | ||||||
| // 		RoomID:   pm["RoomID"], |  | ||||||
| // 		Team:     team, |  | ||||||
| // 		Role:     role, |  | ||||||
| // 	} |  | ||||||
| // 	return saveState(pm["Username"], us) |  | ||||||
| // } |  | ||||||
|  |  | ||||||
| // validateMove checks if it is players turn | // validateMove checks if it is players turn | ||||||
| func validateMove(fi *models.FullInfo, ur models.UserRole) error { | func validateMove(fi *models.FullInfo, ur models.UserRole) error { | ||||||
| 	if fi.State.Role != ur { | 	if fi.State.Role != ur { | ||||||
|   | |||||||
| @@ -248,7 +248,7 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) { | |||||||
| 				return | 				return | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			// TODO: if mark was found, it needs to be removed | 			// if mark was found, it needs to be removed | ||||||
| 			if err := repo.CardMarksRemove(r.Context(), card.ID, fi.State.Username); err != nil { | 			if err := repo.CardMarksRemove(r.Context(), card.ID, fi.State.Username); err != nil { | ||||||
| 				log.Error("failed to remove mark", "error", err, "card", card) | 				log.Error("failed to remove mark", "error", err, "card", card) | ||||||
| 				abortWithError(w, "failed to remove mark") | 				abortWithError(w, "failed to remove mark") | ||||||
|   | |||||||
| @@ -88,17 +88,10 @@ func HandleExit(w http.ResponseWriter, r *http.Request) { | |||||||
| 		creatorLeft = true | 		creatorLeft = true | ||||||
| 	} | 	} | ||||||
| 	exitedRoom := fi.ExitRoom() | 	exitedRoom := fi.ExitRoom() | ||||||
| 	// if err := saveRoom(exitedRoom); err != nil { |  | ||||||
| 	// 	abortWithError(w, err.Error()) |  | ||||||
| 	// 	return |  | ||||||
| 	// } |  | ||||||
| 	if creatorLeft { | 	if creatorLeft { | ||||||
| 		if err := repo.RoomDeleteByID(r.Context(), exitedRoom.ID); err != nil { | 		if err := repo.RoomDeleteByID(r.Context(), exitedRoom.ID); err != nil { | ||||||
| 			log.Error("failed to remove room", "error", err) | 			log.Error("failed to remove room", "error", err) | ||||||
| 		} | 		} | ||||||
| 		// removeRoom(exitedRoom.ID) |  | ||||||
| 		// TODO: notify users if creator left |  | ||||||
| 		// and throw them away |  | ||||||
| 		notify(models.NotifyRoomListUpdate, "") | 		notify(models.NotifyRoomListUpdate, "") | ||||||
| 	} | 	} | ||||||
| 	// scary to update the whole room | 	// scary to update the whole room | ||||||
|   | |||||||
| @@ -316,10 +316,6 @@ func (b *Bot) BotMove() { | |||||||
| 		if err := repo.JournalCreate(context.Background(), &lj); err != nil { | 		if err := repo.JournalCreate(context.Background(), &lj); err != nil { | ||||||
| 			b.log.Warn("failed to write to journal", "entry", lj) | 			b.log.Warn("failed to write to journal", "entry", lj) | ||||||
| 		} | 		} | ||||||
| 		// eventName = models.NotifyRoomUpdatePrefix + room.ID |  | ||||||
| 		// eventPayload = "" |  | ||||||
| 	// TODO: needs to decide if it wants to open the next cardword or end turn |  | ||||||
| 	// or end turn on limit |  | ||||||
| 	default: | 	default: | ||||||
| 		b.log.Error("unexpected role", "role", b.Role, "resp-map", tempMap) | 		b.log.Error("unexpected role", "role", b.Role, "resp-map", tempMap) | ||||||
| 		return | 		return | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								todos.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								todos.md
									
									
									
									
									
								
							| @@ -21,6 +21,8 @@ | |||||||
| - redo card .revealed use: it should mean that card is revealed for everybody, while mime should be able to see cards as is; + | - redo card .revealed use: it should mean that card is revealed for everybody, while mime should be able to see cards as is; + | ||||||
| - better styles and fluff; | - better styles and fluff; | ||||||
| - common auth system between sites; | - common auth system between sites; | ||||||
|  | - signup vs login; | ||||||
|  | - passwords (to room and to login); | ||||||
| === | === | ||||||
| - show in backlog (and with that in prompt to llm) how many cards are left to open, also additional comment: if guess was right; | - show in backlog (and with that in prompt to llm) how many cards are left to open, also additional comment: if guess was right; | ||||||
| - gameover to backlog; | - gameover to backlog; | ||||||
| @@ -80,11 +82,10 @@ | |||||||
| - bot mime makes a clue -> no update in the room for players; + | - bot mime makes a clue -> no update in the room for players; + | ||||||
| - red moves after bot gave (metal - 3) ended after two guesses (showed in logs, that opened 3. double click on the same card? or somewhere counter is not dropped?); the first guess moved counter to 2, in logs only two requests as expected; + | - red moves after bot gave (metal - 3) ended after two guesses (showed in logs, that opened 3. double click on the same card? or somewhere counter is not dropped?); the first guess moved counter to 2, in logs only two requests as expected; + | ||||||
| - bot mime gve a blue -> timer did not start; timer should be in third package, maybe in crons; + | - bot mime gve a blue -> timer did not start; timer should be in third package, maybe in crons; + | ||||||
| - log journal is not shown on the page; | - marks did not clear after end of the turn (feature?) + | ||||||
| - marks did not clear after end of the turn (feature?) |  | ||||||
|  |  | ||||||
| - start new game satrted timer for a mime; (feature? in other cases mime has no timer); | - start new game satrted timer for a mime; (feature? in other cases mime has no timer); | ||||||
| - timer ended and went to 300; | - timer ended and went to 300; | ||||||
| - mime sees the clue input out of turn; | - mime sees the clue input out of turn; (eh) | ||||||
| - there is a problem of two timers, they both could switch turn, but it is not easy to stop them from llmapi or handlers. | - there is a problem of two timers, they both could switch turn, but it is not easy to stop them from llmapi or handlers. + | ||||||
| - journal still does not work; | - journal still does not work; + | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder