Skip to content

Commit

Permalink
internal: make SP and client buildable via top-level CMakeLists
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Jul 3, 2021
1 parent 245903a commit 258d1e8
Show file tree
Hide file tree
Showing 76 changed files with 316 additions and 8,472 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
path = skyrim-platform/submodules/CommonLibSSE
url = https://github.com/Ryan-rsm-McKenzie/CommonLibSSE.git
[submodule "vcpkg"]
path = skyrim-platform/vcpkg
path = vcpkg
url = https://github.com/skyrim-multiplayer/vcpkg.git
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if(WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-sp")
else()
set(VCPKG_TARGET_TRIPLET "x64-linux")
endif()

set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_LIST_DIR}/overlay_triplets")
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/overlay_ports")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")

cmake_minimum_required(VERSION 3.19.1)
project(skymp)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

add_subdirectory(chakra-wrapper)
add_subdirectory(skyrim-platform)
add_subdirectory(skymp5-client)
5 changes: 5 additions & 0 deletions chakra-wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.19.1)
project(chakra-wrapper)

add_library(chakra-wrapper INTERFACE)
target_include_directories(chakra-wrapper INTERFACE ${CMAKE_CURRENT_LIST_DIR})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions skyrim-platform/src/cmake/npm.cmake → cmake/npm.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function(npm_execute_command)
cmake_parse_arguments(A "" "WORKING_DIRECTORY;OUTPUT_VARIABLE;RESULT_VARIABLE" "COMMAND" ${ARGN})
foreach(arg WORKING_DIRECTORY COMMAND)
if ("${A_${arg}}" STREQUAL "")
if("${A_${arg}}" STREQUAL "")
message(FATAL_ERROR "Missing ${arg} argument")
endif()
endforeach()

if (WIN32)
if(WIN32)
set(temp_bat "${CMAKE_CURRENT_BINARY_DIR}/temp.bat")
set(npm_cmd ${temp_bat})
set(npm_arg "")
Expand All @@ -27,8 +27,8 @@ function(npm_execute_command)
# TODO: ERROR_VARIABLE
)

if ("${A_RESULT_VARIABLE}" STREQUAL "")
if (NOT "${npm_result}" STREQUAL "0")
if("${A_RESULT_VARIABLE}" STREQUAL "")
if(NOT "${npm_result}" STREQUAL "0")
message(FATAL_ERROR "npm ${A_COMMAND} exited with ${npm_result}:\n${npm_output}")
endif()
else()
Expand Down
Empty file added overlay_ports/dummy
Empty file.
File renamed without changes.
5 changes: 1 addition & 4 deletions skymp5-client0/.gitignore → skymp5-client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,4 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# skymp5-client.js build
dist_front
.pnp.*
18 changes: 18 additions & 0 deletions skymp5-client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.19.1)
project(skymp5-client)

include(${CMAKE_SOURCE_DIR}/cmake/npm.cmake)

npm_execute_command(
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND install
)

file(GLOB_RECURSE sources ${CMAKE_CURRENT_LIST_DIR}/src/*.ts)

add_custom_target(skymp5-client ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
SOURCES ${sources}
COMMAND npm run build
)
add_dependencies(skymp5-client skyrim-platform)
14 changes: 14 additions & 0 deletions skymp5-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions skymp5-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "skymp5-client",
"version": "1.0.0",
"description": "",
"scripts": {
"watch": "tsc -w",
"build": "tsc"
},
"keywords": [],
"author": "Leonid Pospelov <[email protected]> (https://skymp.io)",
"devDependencies": {
"typescript": "^4.1.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const main = (): void => {

printConsole({ cfg });

const uiPort = cfg.port === 7777 ? 3000 : cfg.port + 1;
const uiPort = cfg.port === 7777 ? 3000 : cfg.port as number + 1;

const url = `http://${cfg.ip}:${uiPort}/ui/index.html`;
printConsole(`loading url ${url}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Actor,
Ammo,
printConsole,
ActorBase,
} from "skyrimPlatform";

import * as structures from "../../lib/structures/inventory";
Expand All @@ -27,7 +28,7 @@ export type BasicEntry = structures.BasicEntry;

// 'loxsword (Legendary)' => 'loxsword'
const getRealName = (s?: string): string => {
if (!s) return s;
if (!s) return s as string;

const arr = s.split(" ");
if (arr.length && arr[arr.length - 1].match(/^\(.*\)$/)) arr.pop();
Expand All @@ -36,7 +37,7 @@ const getRealName = (s?: string): string => {

// 'aaaaaaaaaaaaaaaa' => 'aaa...'
const cropName = (s?: string): string => {
if (!s) return s;
if (!s) return s as string;

const max = 128;
return s.length >= max
Expand Down Expand Up @@ -200,7 +201,7 @@ const getExtraContainerChangesAsInventory = (
};

const getBaseContainerAsInventory = (refr: ObjectReference): Inventory => {
return { entries: getContainer(refr.getBaseObject().getFormID()) };
return { entries: getContainer((refr.getBaseObject() as ActorBase).getFormID()) };
};

const sumInventories = (lhs: Inventory, rhs: Inventory): Inventory => {
Expand Down Expand Up @@ -263,7 +264,7 @@ const basesReset = (): Set<number> => {
storage["basesResetExists"] = true;
storage["basesReset"] = new Set<number>();
}
return storage["basesReset"];
return storage["basesReset"] as Set<number>;
};

const resetBase = (refr: ObjectReference): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ export type Look = structures.Look;
export type Tint = structures.Tint;

export const getLook = (actor: Actor): Look => {
const base = ActorBase.from(actor.getBaseObject());
const base = ActorBase.from(actor.getBaseObject()) as ActorBase;

const hairColor = base.getHairColor();
const skinColor = TESModPlatform.getSkinColor(base);

const newLook: Look = {
isFemale: base.getSex() === 1,
raceId: base.getRace() ? base.getRace().getFormID() : 0,
raceId: base.getRace() ? (base.getRace() as Race).getFormID() : 0,
weight: base.getWeight(),
hairColor: hairColor ? hairColor.getColor() : 0,
headpartIds: [],
headTextureSetId: base.getFaceTextureSet()
? base.getFaceTextureSet().getFormID()
? (base.getFaceTextureSet() as TextureSet).getFormID()
: 0,
options: new Array(19),
presets: new Array(4),
tints: [],
skinColor: skinColor ? skinColor.getColor() : 0,
name: actor.getBaseObject().getName(),
name: (actor.getBaseObject() as ActorBase).getName(),
};

const numHeadparts = base.getNumHeadParts();
Expand All @@ -51,7 +51,7 @@ export const getLook = (actor: Actor): Look => {
}

const numTints =
Game.getPlayer().getFormID() === actor.getFormID()
(Game.getPlayer() as Actor).getFormID() === actor.getFormID()
? Game.getNumTintMasks()
: 0;
for (let i = 0; i < numTints; ++i) {
Expand All @@ -68,7 +68,7 @@ export const getLook = (actor: Actor): Look => {

const isVisible = (argb: number) => argb > 0x00ffffff || argb < 0;

export const applyTints = (actor: Actor, look: Look): void => {
export const applyTints = (actor: Actor | null, look: Look): void => {
if (!look) throw new Error("null look has been passed to applyTints");

const tints = look.tints.filter((t) => isVisible(t.argb));
Expand All @@ -93,7 +93,7 @@ export const applyTints = (actor: Actor, look: Look): void => {
TESModPlatform.pushTintMask(actor, tint.type, tint.argb, tint.texturePath);
});

const playerBaseId = Game.getPlayer().getBaseObject().getFormID();
const playerBaseId = ((Game.getPlayer() as Actor).getBaseObject() as ActorBase).getFormID();

if (actor)
TESModPlatform.setFormIdUnsafe(actor.getBaseObject(), playerBaseId);
Expand Down Expand Up @@ -127,14 +127,17 @@ const applyLookCommon = (look: Look, npc: ActorBase): void => {
};

export const applyLook = (look: Look): ActorBase => {
const npc: ActorBase = TESModPlatform.createNpc();
const npc: ActorBase = TESModPlatform.createNpc() as ActorBase;
if (!npc) throw new Error("createNpc returned null");
applyLookCommon(look, npc);
return npc;
};

export const applyLookToPlayer = (look: Look): void => {
applyLookCommon(look, ActorBase.from(Game.getPlayer().getBaseObject()));
applyLookCommon(
look,
ActorBase.from((Game.getPlayer() as Actor).getBaseObject()) as ActorBase
);
applyTints(null, look);
Game.getPlayer().queueNiNodeUpdate();
(Game.getPlayer() as Actor).queueNiNodeUpdate();
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Game,
TESModPlatform,
Debug,
Form,
} from "skyrimPlatform";
import { Movement, RunMode, AnimationVariables, Transform } from "./movement";

Expand All @@ -15,7 +16,7 @@ export const applyMovement = (refr: ObjectReference, m: Movement): void => {
const ac = Actor.from(refr);

if (ac) {
let lookAt: Actor | null;
let lookAt: Actor | null = undefined as unknown as Actor;
if (m.lookAt) {
try {
lookAt = Game.findClosestActor(
Expand All @@ -29,7 +30,7 @@ export const applyMovement = (refr: ObjectReference, m: Movement): void => {
}
}

if (lookAt) {
if (lookAt as Actor) {
ac.setHeadTracking(true);
ac.setLookAt(lookAt, false);
} else {
Expand Down Expand Up @@ -162,7 +163,7 @@ const cellWidth = 4096;

const isInDifferentExteriorCell = (refr: ObjectReference, pos: number[]) => {
const currentPos = getPos(refr);
const playerPos = getPos(Game.getPlayer());
const playerPos = getPos(Game.getPlayer() as Actor);
const targetDistanceToPlayer = getDistance(playerPos, pos);
const currentDistanceToPlayer = getDistance(playerPos, currentPos);
return (
Expand All @@ -175,7 +176,7 @@ const isInDifferentWorldOrCell = (
worldOrCell: number
) => {
return (
worldOrCell !== (refr.getWorldSpace() || refr.getParentCell()).getFormID()
worldOrCell !== ((refr.getWorldSpace() || refr.getParentCell()) as Form).getFormID()
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ObjectReference, Actor, TESModPlatform } from "skyrimPlatform";
import { ObjectReference, Actor, TESModPlatform, Form } from "skyrimPlatform";
import { NiPoint3 } from "../../lib/structures/movement";
import { Movement, RunMode } from "./movement";

export const getMovement = (refr: ObjectReference): Movement => {
const ac = Actor.from(refr);
const ac = Actor.from(refr) as Actor;

// It is running for ObjectReferences because Standing
// Doesn't lead to translateTo call
Expand All @@ -27,19 +27,19 @@ export const getMovement = (refr: ObjectReference): Movement => {
}

return {
worldOrCell: (refr.getWorldSpace() || refr.getParentCell()).getFormID(),
worldOrCell: ((refr.getWorldSpace() || refr.getParentCell()) as Form).getFormID(),
pos: [refr.getPositionX(), refr.getPositionY(), refr.getPositionZ()],
rot: [refr.getAngleX(), refr.getAngleY(), refr.getAngleZ()],
runMode: runMode,
direction:
runMode !== "Standing"
? 360 * refr.getAnimationVariableFloat("Direction")
: 0,
isInJumpState: ac && ac.getAnimationVariableBool("bInJumpState"),
isSneaking: ac && isSneaking(ac),
isBlocking: ac && ac.getAnimationVariableBool("IsBlocking"),
isWeapDrawn: ac && ac.isWeaponDrawn(),
healthPercentage,
isInJumpState: (ac && ac.getAnimationVariableBool("bInJumpState")) as boolean,
isSneaking: (ac && isSneaking(ac)) as boolean,
isBlocking: (ac && ac.getAnimationVariableBool("IsBlocking")) as boolean,
isWeapDrawn: (ac && ac.isWeaponDrawn()) as boolean,
healthPercentage: healthPercentage as number,
lookAt,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ const getCommandExecutor = (
send({ t: MsgType.ConsoleCommand, data: { commandName, args } });
if (
storage["_api_onConsoleCommand"] &&
storage["_api_onConsoleCommand"]["callback"]
(storage["_api_onConsoleCommand"] as any)["callback"]
) {
if (commandName === "mp") {
try {
storage["_api_onConsoleCommand"]["callback"](...args);
(storage["_api_onConsoleCommand"] as any)["callback"](...args);
} catch (e) {
printConsole("'_api_onConsoleCommand' - ", e);
}
Expand All @@ -92,12 +92,12 @@ export const setUpConsoleCommands = (
findConsoleCommand(" ConfigureUM") || findConsoleCommand("test");
if (command) {
command.shortName = "mp";
command.execute = getCommandExecutor("mp", send, localIdToRemoteId);
command.execute = getCommandExecutor("mp", send, localIdToRemoteId) as (...args: unknown[]) => boolean;
}

Object.keys(schemas).forEach((commandName: CmdName) => {
(Object.keys(schemas) as any[]).forEach((commandName: CmdName) => {
const command = findConsoleCommand(commandName);
if (!command || nonVanilaCommands.includes(commandName)) return;
command.execute = getCommandExecutor(commandName, send, localIdToRemoteId);
command.execute = getCommandExecutor(commandName, send, localIdToRemoteId) as (...args: unknown[]) => boolean;
});
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { hooks, Game, printConsole } from "skyrimPlatform";
import { hooks, Game, printConsole,Actor } from "skyrimPlatform";

let gAllowGetUp = true;

export const update = (): void => {
gAllowGetUp = Game.getPlayer().getActorValuePercentage("health") >= 0.05;
gAllowGetUp = (Game.getPlayer() as Actor).getActorValuePercentage("health") >= 0.05;
};

hooks.sendAnimationEvent.add({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { storage } from "skyrimPlatform";
storage["hostAttempts"] = [];

export const tryHost = (targetRemoteId: number): void => {
storage["hostAttempts"].push(targetRemoteId);
(storage["hostAttempts"] as any).push(targetRemoteId);
};

export const nextHostAttempt = (): number | undefined => {
Expand Down
Loading

0 comments on commit 258d1e8

Please sign in to comment.