Commit 3fc9d28e authored by Samuel Fawcett's avatar Samuel Fawcett
Browse files

Merge branch 'append-inputenabled' into 'main'

Non-blocking appends

Closes #40

See merge request redpointgames/a-momentary-meeting!32
parents cb88e6f3 057183c6
Subproject commit 39ceacc91fd41d1013185a350d84726f5aaa668f
Subproject commit 9d398abec5807f8646eb036bc0e6a243ceea9c8d
......@@ -508,7 +508,7 @@ namespace MomentaryMeeting.Game
else
{
string content = command.Substring(verb.Length + 1);
string message = $">The Stranger says: {content}";
string message = $"<The Stranger says: {content}";
Meeting meeting = _interactionManager.FindMeeting(player);
foreach (UserModel other in meeting._users)
{
......
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Game.Interactions;
using MomentaryMeeting.Game.Interactions;
using MomentaryMeeting.Models;
using MomentaryMeeting.Services;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting);
}
public class InteractionManager : IEndMeetings
{
private const string _entryText = "A stranger appears in front of you.";
private readonly IDatabaseApi _databaseApi;
private readonly Database _database;
private readonly ILogger<InteractionManager> _logger;
private readonly ArrangementGenerator _arrangementGenerator;
private List<Meeting> _meetings;
private GameInstance _gameInstance;
public InteractionManager(IDatabaseApi databaseApi, ILogger<InteractionManager> logger, ArrangementGenerator arrangementGenerator)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
_logger = logger;
_arrangementGenerator = arrangementGenerator;
_meetings = new List<Meeting>();
}
public async Task<string> CheckForInteraction(GameInstance gameInstance, UserModel player)
{
if (_gameInstance == null)
_gameInstance = gameInstance;
foreach(UserModel otherUser in gameInstance.GetPlayers())
{
_logger.LogInformation($"ID: {player.DiscordId} {otherUser.DiscordId} {player.DiscordId != otherUser.DiscordId} object: {player != otherUser}");
// if someone else is in the room, and they are not me and they are not in meeting
if (otherUser.LocationName == player.LocationName && player.DiscordId != otherUser.DiscordId && otherUser.InMeeting == false)
{
player.InMeeting = true;
otherUser.InMeeting = true;
Meeting meeting = new Meeting(this);
meeting._users.Add(player);
meeting._users.Add(otherUser);
_meetings.Add(meeting);
// let them know someone has entered their room
await _gameInstance.SendPromptToPlayer(otherUser, ">" + _entryText);
await _gameInstance.SyncPlayerMusic(_gameInstance.GetConnection(otherUser.DiscordId));
_logger.LogInformation("User(" + player.DiscordId + ":" + player.Username +
") has entered a room occupied by " + "User(" + otherUser.DiscordId + ":" + otherUser.Username + "). Beginning meeting!");
return _entryText;
}
}
return null;
}
public async Task EndMeeting(Meeting meeting)
{
_logger.LogInformation("Ending meeting between " + meeting._users[0] + " and " + meeting._users[1]);
foreach (UserModel player in meeting._users)
{
player.InMeeting = false;
_meetings.Remove(meeting);
// send them two rooms away
ArrangementGenerator.Neighbours neighbours;
string newRoom = player.LocationName;
int roomDistance = 3;
for (int i = 0; i < roomDistance; i++)
{
neighbours = _arrangementGenerator.GetNeighbours(newRoom);
List<string> rooms = new List<string>();
string northNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.North);
if (northNeighbour != "")
rooms.Add(northNeighbour);
string southNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.South);
if (southNeighbour != "")
rooms.Add(southNeighbour);
string eastNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.East);
if (eastNeighbour != "")
rooms.Add(eastNeighbour);
string westNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.West);
if (westNeighbour != "")
rooms.Add(westNeighbour);
newRoom = rooms[new Random().Next(rooms.Count)];
}
player.LocationName = newRoom;
await _gameInstance.NotifyPlayerOfMeetingEnd(player.DiscordId);
}
_gameInstance.GenerateAndNotify();
}
public Meeting FindMeeting(UserModel aUser)
{
foreach(Meeting meeting in _meetings)
{
if (meeting._users.Contains(aUser))
return meeting;
}
_logger.LogError($"Couldn't find meeting for userid: {aUser.DiscordId}");
return null;
}
}
}
<<<<<<< Updated upstream
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting);
}
public class InteractionManager : IEndMeetings
{
private const string _entryText = "A stranger appears in front of you.";
private readonly IDatabaseApi _databaseApi;
private readonly Database _database;
private readonly ILogger<InteractionManager> _logger;
private readonly ArrangementGenerator _arrangementGenerator;
private List<Meeting> _meetings;
private GameInstance _gameInstance;
public InteractionManager(IDatabaseApi databaseApi, ILogger<InteractionManager> logger, ArrangementGenerator arrangementGenerator)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
_logger = logger;
_arrangementGenerator = arrangementGenerator;
_meetings = new List<Meeting>();
}
public async Task<string> CheckForInteraction(GameInstance gameInstance, UserModel player)
{
if (_gameInstance == null)
_gameInstance = gameInstance;
foreach(UserModel otherUser in gameInstance.GetPlayers())
{
_logger.LogInformation($"ID: {player.DiscordId} {otherUser.DiscordId} {player.DiscordId != otherUser.DiscordId} object: {player != otherUser}");
// if someone else is in the room, and they are not me and they are not in meeting
if (otherUser.LocationName == player.LocationName && player.DiscordId != otherUser.DiscordId && otherUser.InMeeting == false)
{
player.InMeeting = true;
otherUser.InMeeting = true;
Meeting meeting = new Meeting(this);
meeting._users.Add(player);
meeting._users.Add(otherUser);
_meetings.Add(meeting);
// let them know someone has entered their room
await _gameInstance.SendPromptToPlayer(otherUser, "<" + _entryText);
await _gameInstance.SyncPlayerMusic(_gameInstance.GetConnection(otherUser.DiscordId));
_logger.LogInformation("User(" + player.DiscordId + ":" + player.Username +
") has entered a room occupied by " + "User(" + otherUser.DiscordId + ":" + otherUser.Username + "). Beginning meeting!");
return _entryText;
}
}
return null;
}
public async Task EndMeeting(Meeting meeting)
{
_logger.LogInformation("Ending meeting between " + meeting._users[0] + " and " + meeting._users[1]);
foreach (UserModel player in meeting._users)
{
player.InMeeting = false;
_meetings.Remove(meeting);
// send them two rooms away
ArrangementGenerator.Neighbours neighbours;
string newRoom = player.LocationName;
int roomDistance = 3;
for (int i = 0; i < roomDistance; i++)
{
neighbours = _arrangementGenerator.GetNeighbours(newRoom);
List<string> rooms = new List<string>();
string northNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.North);
if (northNeighbour != "")
rooms.Add(northNeighbour);
string southNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.South);
if (southNeighbour != "")
rooms.Add(southNeighbour);
string eastNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.East);
if (eastNeighbour != "")
rooms.Add(eastNeighbour);
string westNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.West);
if (westNeighbour != "")
rooms.Add(westNeighbour);
newRoom = rooms[new Random().Next(rooms.Count)];
}
player.LocationName = newRoom;
await _gameInstance.NotifyPlayerOfMeetingEnd(player.DiscordId);
}
_gameInstance.GenerateAndNotify();
}
public Meeting FindMeeting(UserModel aUser)
{
foreach(Meeting meeting in _meetings)
{
if (meeting._users.Contains(aUser))
return meeting;
}
_logger.LogError($"Couldn't find meeting for userid: {aUser.DiscordId}");
return null;
}
}
}
=======
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting);
}
public class InteractionManager : IEndMeetings
{
private const string _entryText = "A stranger appears in front of you.";
private readonly IDatabaseApi _databaseApi;
private readonly Database _database;
private readonly ILogger<InteractionManager> _logger;
private readonly ArrangementGenerator _arrangementGenerator;
private List<Meeting> _meetings;
private GameInstance _gameInstance;
public InteractionManager(IDatabaseApi databaseApi, ILogger<InteractionManager> logger, ArrangementGenerator arrangementGenerator)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
_logger = logger;
_arrangementGenerator = arrangementGenerator;
_meetings = new List<Meeting>();
}
public async Task<string> CheckForInteraction(GameInstance gameInstance, UserModel player)
{
if (_gameInstance == null)
_gameInstance = gameInstance;
foreach(UserModel otherUser in gameInstance.GetPlayers())
{
_logger.LogInformation($"ID: {player.DiscordId} {otherUser.DiscordId} {player.DiscordId != otherUser.DiscordId} object: {player != otherUser}");
// if someone else is in the room, and they are not me and they are not in meeting
if (otherUser.LocationName == player.LocationName && player.DiscordId != otherUser.DiscordId && otherUser.InMeeting == false)
{
player.InMeeting = true;
otherUser.InMeeting = true;
Meeting meeting = new Meeting(this);
meeting._users.Add(player);
meeting._users.Add(otherUser);
_meetings.Add(meeting);
// let them know someone has entered their room
await _gameInstance.SendPromptToPlayer(otherUser, ">" + _entryText);
await _gameInstance.SyncPlayerMusic(_gameInstance.GetConnection(otherUser.DiscordId));
_logger.LogInformation("User(" + player.DiscordId + ":" + player.Username +
") has entered a room occupied by " + "User(" + otherUser.DiscordId + ":" + otherUser.Username + "). Beginning meeting!");
return _entryText;
}
}
return null;
}
public async Task EndMeeting(Meeting meeting)
{
_logger.LogInformation("Ending meeting between " + meeting._users[0] + " and " + meeting._users[1]);
foreach (UserModel player in meeting._users)
{
player.InMeeting = false;
_meetings.Remove(meeting);
// send them two rooms away
ArrangementGenerator.Neighbours neighbours;
string newRoom = player.LocationName;
int roomDistance = 3;
for (int i = 0; i < roomDistance; i++)
{
neighbours = _arrangementGenerator.GetNeighbours(newRoom);
List<string> rooms = new List<string>();
string northNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.North);
if (northNeighbour != "")
rooms.Add(northNeighbour);
string southNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.South);
if (southNeighbour != "")
rooms.Add(southNeighbour);
string eastNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.East);
if (eastNeighbour != "")
rooms.Add(eastNeighbour);
string westNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.West);
if (westNeighbour != "")
rooms.Add(westNeighbour);
newRoom = rooms[new Random().Next(rooms.Count)];
}
player.LocationName = newRoom;
await _gameInstance.NotifyPlayerOfMeetingEnd(player.DiscordId);
}
_gameInstance.GenerateAndNotify();
}
public Meeting FindMeeting(UserModel aUser)
{
foreach(Meeting meeting in _meetings)
{
if (meeting._users.Contains(aUser))
return meeting;
}
_logger.LogError($"Couldn't find meeting for userid: {aUser.DiscordId}");
return null;
}
}
}
>>>>>>> Stashed changes
......@@ -12,6 +12,7 @@ let authenticated = window.authenticated;
let ws = null;
let textSpeedModifier = 1;
let textSpeedToggle = 0;
let sayAppend = false;
let pendingMusicChange = null;
let currentTrackId, currentMeetingTrackId;
......@@ -180,7 +181,9 @@ function typeNextCharacter() {
if (currentText !== targetText) {
currentText += takeNextCharacter(targetText, currentText.length);
// turn of input display
$("#input_bar").hide();
if (!sayAppend) {
$("#input_bar").hide();
}
let fadedCount = -1;
let processingPosition = 0;
......@@ -338,7 +341,7 @@ function typeNextCharacter() {
};
window.addEventListener("keydown", function (ev) {
if (currentText !== targetText) {
if (currentText !== targetText && !sayAppend) { //additionally checks if currently writing an append for say command so input is only hiding in other circumstances
return; // do not want player typing while description is writing itself
}
//console.log("Key code: " + ev.keyCode); // for checking key codes when debugging input stuff
......@@ -505,7 +508,11 @@ if (authenticated) {
};
} else {
// if append mode (starts with '>') append instead of replace target text
if (event.data[0] === '>') {
if (event.data[0] === '>' || event.data[0] === '<') {
sayAppend = false; // not a say append event
if (event.data[0] === '<') { // using < as 'say append' character
sayAppend = true;
}
// this pending music change needs to happen once the target text has been typed out, pre-append
if (pendingMusicChange !== null) {
pendingMusicChange.targetCharacterCount = targetText.length;
......@@ -514,6 +521,7 @@ if (authenticated) {
targetText += "\n\n" + event.data.substr(1);
}
else {
sayAppend = false; // not a say append event
if (pendingMusicChange !== null) {
changeTrack(pendingMusicChange.track, pendingMusicChange.inMeeting);
pendingMusicChange = null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment