Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #368

Merged
merged 12 commits into from
Nov 30, 2024
Binary file modified Content/Buildings/-Shared/BP_ModuleHoloWithCompass_def.uasset
Binary file not shown.
Binary file modified Content/Buildings/-Shared/BP_TestArrow.uasset
Binary file not shown.
Binary file modified Content/Buildings/-Shared/MI_ArrowFont.uasset
Binary file not shown.
Binary file modified Content/Buildings/-Shared/MI_UpArrow.uasset
Binary file not shown.
Binary file modified Content/Buildings/-Shared/M_ArrowFont.uasset
Binary file not shown.
Binary file modified Content/Buildings/-Shared/M_ArrowMaterial.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion FicsItNetworks.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"FileVersion": 3,
"Version": 0,
"VersionName": "0.3",
"SemVersion": "0.3.30",
"SemVersion": "0.3.31",
"FriendlyName": "FicsIt-Networks",
"Description": "Adds a computer network and programmable computers to the Game.",
"Category": "Modding",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void UFINWirelessAccessPointActorRepresentation::Setup(UFINWirelessAccessPointCo
this->mRepresentationText = Connection->GetRepresentationText();
this->mRepresentationColor = Connection->Data.IsConnected && Connection->Data.IsInRange ? Green : Connection->Data.IsInRange ? Orange : Red;
this->mRepresentationTexture = LoadObject<UTexture2D>(NULL, TEXT("/FicsItNetworks/Buildings/Network/WirelessAccessPoint/UI/Assets/TXUI_FIN_Wifi_MapCompassIcon.TXUI_FIN_Wifi_MapCompassIcon"));
this->mRepresentationCompassMaterial = LoadObject<UMaterialInterface>(NULL, TEXT("/FicsItNetworks/Buildings/Network/WirelessAccessPoint/UI/Assets/MI_CompassIcon_Wifi.MI_CompassIcon_Wifi"));
//this->mRealActor = Connection->RadarTower.Get();
this->mIsStatic = true;
this->mActorRotation = FRotator::ZeroRotator;
Expand All @@ -18,7 +19,7 @@ void UFINWirelessAccessPointActorRepresentation::Setup(UFINWirelessAccessPointCo

// We use RT_StartingPod since RT_Default destroys automatically the ActorRepresentation after 10 seconds
// Cannot use RT_MapMarker since it opens the marker editor when clicked.
this->mRepresentationType = ERepresentationType::RT_StartingPod;
this->mRepresentationType = ERepresentationType::RT_MapMarker;
}

void UFINWirelessAccessPointActorRepresentation::SetupActorRepresentation(AActor* realActor, bool isLocal, float lifeSpan) {}
Expand Down
57 changes: 57 additions & 0 deletions Source/FicsItNetworksComputer/Private/CMD/FINCMDLocateComputer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "CoreMinimal.h"
#include "AkGameplayStatics.h"
#include "FGAttentionPingActor.h"
#include "FGPlayerController.h"
#include "FicsItNetworksComputer.h"
#include "FINComputerCase.h"
#include "FINNetworkComponent.h"
#include "FINNetworkUtils.h"
#include "Kismet/GameplayStatics.h"

bool ExecCMDLocateComputer(UWorld* World, const TCHAR* Command, FOutputDevice& Ar) {
if (FParse::Command(&Command, TEXT("FINLocateComputer"))) {
FString computerStr = FParse::Token(Command, true);

TArray<AActor*> actors;
UGameplayStatics::GetAllActorsOfClass(World, AFINComputerCase::StaticClass(), actors);

AFINComputerCase* computer = nullptr;
FGuid uuid;
if (FGuid::Parse(computerStr, uuid)) {
for (AActor* actor : actors) {
UObject* networkComponent = UFINNetworkUtils::FindNetworkComponentFromObject(actor);
if (IFINNetworkComponent::Execute_GetID(networkComponent) == uuid) {
computer = Cast<AFINComputerCase>(actor);
break;
}
}
} else {
for (AActor* actor : actors) {
if (actor->GetName() == computerStr) {
computer = Cast<AFINComputerCase>(actor);
break;
}
}
}
if (computer == nullptr) {
UE_LOG(LogFicsItNetworksComputer, Display, TEXT("Unable to locate FicsIt-Networks Computer '%s'"), *computerStr);
return true;
}

FVector Position = computer->GetActorLocation();
UE_LOG(LogFicsItNetworksComputer, Display, TEXT("Located FicsIt-Networks Computer '%s' at: %f %f %f"), *computerStr, Position.X, Position.Y, Position.Z);

for (auto players = World->GetPlayerControllerIterator(); players; ++players) {
AFGPlayerController* PlayerController = Cast<AFGPlayerController>(players->Get());
UClass* Class = LoadObject<UClass>(nullptr, TEXT("/Game/FactoryGame/Character/Player/BP_AttentionPingActor.BP_AttentionPingActor_C"));
AFGAttentionPingActor* PingActor = PlayerController->GetWorld()->SpawnActorDeferred<AFGAttentionPingActor>(Class, FTransform(Position));
PingActor->SetOwningPlayerState(PlayerController->GetPlayerState<AFGPlayerState>());
PingActor->FinishSpawning(FTransform(Position));
}

return true;
}
return false;
}

[[maybe_unused]] static FStaticSelfRegisteringExec SelfRegisterCMDLocateComputer(&ExecCMDLocateComputer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "CoreMinimal.h"
#include "AkGameplayStatics.h"
#include "FicsItNetworksComputer.h"
#include "FINComputerCase.h"
#include "Kismet/GameplayStatics.h"

bool ExecCMDRestartAllComputers(UWorld* World, const TCHAR* Command, FOutputDevice& Ar) {
if (FParse::Command(&Command, TEXT("FINRestartAllComputers"))) {
UE_LOG(LogFicsItNetworksComputer, Display, TEXT("Restarting all FicsIt-Networks Computers..."));

TArray<AActor*> actors;
UGameplayStatics::GetAllActorsOfClass(World, AFINComputerCase::StaticClass(), actors);
for (AActor* actor : actors) {
AFINComputerCase* computer = Cast<AFINComputerCase>(actor);
if (!computer || !computer->Kernel) continue;
computer->Kernel->Reset();
}

return true;
}
return false;
}

[[maybe_unused]] static FStaticSelfRegisteringExec SelfRegisterCMDRestartAllComputers(&ExecCMDRestartAllComputers);
28 changes: 0 additions & 28 deletions Source/FicsItNetworksLua/Private/FINLua/API/LuaComputerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,6 @@ namespace FINLua {
*
* The Computer Library provides functions for interaction with the computer and especially the Lua Runtime.
*/)", computer) {
LuaModuleTableFunction(R"(/**
* @LuaFunction reset()
* @DisplayName Reset
*
* Stops the current code execution immediately and queues the system to restart in the next tick.
*/)", reset) {
FFINLuaRuntime* runtime = &luaFIN_getRuntime(L);
runtime->TickActions.Enqueue([runtime]() {
runtime->Reset();
});
return lua_yield(L, 0);
}

LuaModuleTableFunction(R"(/**
* @LuaFunction stop()
* @DisplayName Stop
*
* Stops the current code execution. +
* Basically kills the PC runtime immediately.
*/)", stop) {
FFINLuaRuntime& runtime = luaFIN_getRuntime(L);
runtime.TickActions.Enqueue([]() {
//kernel->Stop();
// TODO: Fix computer.stop()
});
return lua_yield(L, 0);
}

LuaModuleTableFunction(R"(/**
* @LuaFunction skip()
* @DisplayName Skip
Expand Down
30 changes: 30 additions & 0 deletions Source/FicsItNetworksLua/Private/FINLua/API/LuaKernelAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,36 @@ namespace FINLua {
return 1;
}

LuaModuleTableFunction(R"(/**
* @LuaFunction reset()
* @DisplayName Reset
*
* Stops the current code execution immediately and queues the system to restart in the next tick.
*/)", reset) {
FFINLuaRuntime& runtime = luaFIN_getRuntime(L);
UFINKernelSystem* kernel = luaFIN_getKernel(L);
runtime.TickActions.Enqueue([kernel]() {
kernel->Reset();
});
return lua_yield(L, 0);
}

LuaModuleTableFunction(R"(/**
* @LuaFunction stop()
* @DisplayName Stop
*
* Stops the current code execution. +
* Basically kills the PC runtime immediately.
*/)", stop) {
FFINLuaRuntime& runtime = luaFIN_getRuntime(L);
UFINKernelSystem* kernel = luaFIN_getKernel(L);

runtime.TickActions.Enqueue([kernel]() {
kernel->Stop();
});
return lua_yield(L, 0);
}

LuaModuleTableFunction(R"(/**
* @LuaFunction setEEPROM(code: string)
* @DisplayName Set EEPROM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FFINLuaThreadedRuntime::FFINLuaThreadedRuntime() : LuaTask(FAsyncTask<FFINLuaTic
PauseAndWait();
});
Runtime.OnPostReset.AddLambda([this]() {
if (Runtime.GetLuaState() == nullptr) return;
SetShouldBePromoted(false);
FINLua::luaFIN_setThreadedRuntime(Runtime.GetLuaState(), *this);
});
Expand Down
26 changes: 13 additions & 13 deletions Source/FicsItNetworksLua/Private/FINLuaProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ UFINLuaProcessor::UFINLuaProcessor() {
FINLua::luaFIN_setFileSystem(Runtime.Runtime.GetLuaState(), GetKernel()->GetFileSystem());
FINLua::luaFIN_setEventSystem(Runtime.Runtime.GetLuaState(), EventSystem);
});
Runtime.Runtime.OnPostReset.AddWeakLambda(this, [this]() {
TOptional<FString> error = Runtime.Runtime.LoadState(RuntimeState);
if (error) {
GetKernel()->Reset();
FString message = FString::Printf(TEXT("%s: Unable to load computer state from save-file (computer will restart): %s"), *DebugInfo, **error);
UE_LOG(LogFicsItNetworksLua, Display, TEXT("%s"), *message);
GetKernel()->GetLog()->PushLogEntry(FIL_Verbosity_Warning, message);
}
});

ComponentNetwork.OnGetComponentByID.BindWeakLambda(this, [this](const FGuid& ID) {
return GetKernel()->GetNetwork()->GetComponentByID(ID);
Expand Down Expand Up @@ -129,13 +138,6 @@ void UFINLuaProcessor::PreLoadGame_Implementation(int32 saveVersion, int32 gameV

void UFINLuaProcessor::PostLoadGame_Implementation(int32 saveVersion, int32 gameVersion) {
Runtime.Runtime.Reset();
TOptional<FString> error = Runtime.Runtime.LoadState(RuntimeState);
if (error) {
GetKernel()->Reset();
FString message = FString::Printf(TEXT("%s: Unable to load computer state from save-file (computer will restart): %s"), *DebugInfo, **error);
UE_LOG(LogFicsItNetworksLua, Display, TEXT("%s"), *message);
GetKernel()->GetLog()->PushLogEntry(FIL_Verbosity_Warning, message);
}
}

void UFINLuaProcessor::SetKernel(UFINKernelSystem* InKernel) {
Expand Down Expand Up @@ -167,15 +169,13 @@ void UFINLuaProcessor::Stop(bool bIsCrash) {
}

void UFINLuaProcessor::Reset() {
RuntimeState.LuaData = TEXT("");

Runtime.Runtime.Reset();

TOptional<FString> Code = GetEEPROM();
if (Code) {
TOptional<FString> error = Runtime.Runtime.LoadCode(*Code);
if (error) {
Kernel->Crash(MakeShared<FFINKernelCrash>(*error));
}
} else {
Kernel->Crash(MakeShared<FFINKernelCrash>(TEXT("Invalid EEPROM!")));
Runtime.Runtime.LoadCode(*Code);
}
}

Expand Down
7 changes: 0 additions & 7 deletions docs/modules/ROOT/pages/lua/api/ComputerModule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ Returns some kind of strange/mysterious time data from a unknown place (the real
!===
====

=== __computer.__**reset** ()
Stops the current code execution immediately and queues the system to restart in the next tick.

=== __computer.__**skip** ()
This function can be used to skip the current lua tick prematurely.
Mostly for people who want to optimize their games runtime performance.

=== __computer.__**stop** ()
Stops the current code execution. +
Basically kills the PC runtime immediately.

7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/lua/api/KernelModule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@ Returns the amount of milliseconds passed since the system started.
=== __computer.__**panic** (error: string)
Crashes the computer with the given error message.

=== __computer.__**reset** ()
Stops the current code execution immediately and queues the system to restart in the next tick.

=== __computer.__**setEEPROM** (code: string)
Sets the code of the current eeprom. Doesn¬タルt cause a system reset.

=== __computer.__**stop** ()
Stops the current code execution. +
Basically kills the PC runtime immediately.

=== **filesystem**


Expand Down
Loading