Compare commits
2 Commits
a0b619562c
...
7b286806d0
Author | SHA1 | Date | |
---|---|---|---|
|
7b286806d0 | ||
|
d6b3ffa308 |
|
@ -1,4 +1,4 @@
|
||||||
import {Ecs} from './ecs/index.js';
|
import {Ecs} from '@/ecs/index.js';
|
||||||
|
|
||||||
export default class Cell {
|
export default class Cell {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {useEffect, useRef, useState} from 'react';
|
import {useEffect, useRef, useState} from 'react';
|
||||||
|
|
||||||
import {RESOLUTION} from '../constants.js';
|
import {RESOLUTION} from '@/constants.js';
|
||||||
|
|
||||||
import styles from './dom.module.css';
|
import styles from './dom.module.css';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import Slot from './slot.jsx';
|
|
||||||
|
|
||||||
import styles from './hotbar.module.css';
|
import styles from './hotbar.module.css';
|
||||||
|
import Slot from './slot.jsx';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hotbar. 10 slots of inventory with an active selection.
|
* The hotbar. 10 slots of inventory with an active selection.
|
||||||
|
|
|
@ -4,13 +4,13 @@ import {
|
||||||
} from '@pixi/react';
|
} from '@pixi/react';
|
||||||
import {useContext, useEffect, useState} from 'react';
|
import {useContext, useEffect, useState} from 'react';
|
||||||
|
|
||||||
import {RESOLUTION} from '../constants.js';
|
import {RESOLUTION} from '@/constants.js';
|
||||||
import ClientContext from '../context/client.js';
|
import ClientContext from '@/context/client.js';
|
||||||
|
import {Ecs} from '@/ecs/index.js';
|
||||||
|
|
||||||
import Entities from './entities.jsx';
|
import Entities from './entities.jsx';
|
||||||
import styles from './pixi.module.css';
|
import styles from './pixi.module.css';
|
||||||
|
|
||||||
import {Ecs} from '../ecs/index.js';
|
|
||||||
|
|
||||||
export default function Pixi() {
|
export default function Pixi() {
|
||||||
const client = useContext(ClientContext);
|
const client = useContext(ClientContext);
|
||||||
const [entities, setEntities] = useState([]);
|
const [entities, setEntities] = useState([]);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {useEffect, useState} from 'react';
|
import {useEffect, useState} from 'react';
|
||||||
|
|
||||||
import ClientContext from '../context/client.js';
|
import ClientContext from '@/context/client.js';
|
||||||
|
|
||||||
import Title from './title.jsx';
|
import Title from './title.jsx';
|
||||||
import Ui from './ui.jsx';
|
import Ui from './ui.jsx';
|
||||||
|
|
||||||
|
@ -15,10 +16,10 @@ export default function Silphius() {
|
||||||
let Client;
|
let Client;
|
||||||
switch (connectionTuple[0]) {
|
switch (connectionTuple[0]) {
|
||||||
case 'local':
|
case 'local':
|
||||||
({default: Client} = await import('../net/client/local.js'));
|
({default: Client} = await import('@/net/client/local.js'));
|
||||||
break;
|
break;
|
||||||
case 'remote':
|
case 'remote':
|
||||||
({default: Client} = await import('../net/client/remote.js'));
|
({default: Client} = await import('@/net/client/remote.js'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const client = new Client();
|
const client = new Client();
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import {useContext, useEffect} from 'react';
|
import {useContext, useEffect} from 'react';
|
||||||
|
|
||||||
import addKeyListener from '../add-key-listener.js';
|
import addKeyListener from '@/add-key-listener.js';
|
||||||
import {ACTION_MAP, RESOLUTION} from '../constants.js';
|
import {ACTION_MAP, RESOLUTION} from '@/constants.js';
|
||||||
import ClientContext from '../context/client.js';
|
import ClientContext from '@/context/client.js';
|
||||||
|
|
||||||
import Dom from './dom.jsx';
|
import Dom from './dom.jsx';
|
||||||
import Pixi from './pixi.jsx';
|
import Pixi from './pixi.jsx';
|
||||||
import styles from './ui.module.css';
|
import styles from './ui.module.css';
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
export const CLIENT_LATENCY = 100;
|
||||||
|
|
||||||
export const RESOLUTION = [
|
export const RESOLUTION = [
|
||||||
800,
|
800,
|
||||||
450,
|
450,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const SERVER_LATENCY = 100;
|
||||||
|
|
||||||
|
export const TPS = 60;
|
||||||
|
|
||||||
export const ACTION_MAP = {
|
export const ACTION_MAP = {
|
||||||
w: 'moveUp',
|
w: 'moveUp',
|
||||||
d: 'moveRight',
|
d: 'moveRight',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export {default as Action} from '../net/packet/action.js';
|
export {default as Action} from '@/net/packet/action.js';
|
||||||
export {default as Connect} from '../net/packet/connect.js';
|
export {default as Connect} from '@/net/packet/connect.js';
|
||||||
export {default as Connected} from '../net/packet/connected.js';
|
export {default as Connected} from '@/net/packet/connected.js';
|
||||||
export {default as Tick} from '../net/packet/tick.js';
|
export {default as Tick} from '@/net/packet/tick.js';
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {createElement} from 'react';
|
import {createElement} from 'react';
|
||||||
import {createRoot} from 'react-dom/client';
|
import {createRoot} from 'react-dom/client';
|
||||||
|
|
||||||
import Silphius from './components/silphius.jsx';
|
import Silphius from '@/components/silphius.jsx';
|
||||||
|
|
||||||
await import('./isomorphinit.js');
|
await import('@/isomorphinit.js');
|
||||||
|
|
||||||
// Setup DOM.
|
// Setup DOM.
|
||||||
createRoot(document.querySelector('.silphius'))
|
createRoot(document.querySelector('.silphius'))
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
// Gathering.
|
// Gathering.
|
||||||
const {default: PacketClass} = await import('./net/packet/packet.js');
|
const {default: PacketClass} = await import('@/net/packet/packet.js');
|
||||||
Object.values(await import('./gathered/packets.js'))
|
Object.values(await import('@/gathered/packets.js'))
|
||||||
.forEach((Packet) => {
|
.forEach((Packet) => {
|
||||||
PacketClass.register(Packet);
|
PacketClass.register(Packet);
|
||||||
});
|
});
|
||||||
PacketClass.mapRegistered();
|
PacketClass.mapRegistered();
|
||||||
|
|
||||||
const {default: Ecs} = await import('./ecs/ecs.js');
|
const {default: Ecs} = await import('@/ecs/ecs.js');
|
||||||
Ecs.ComponentLikesAndOrBundleLikes = Object.fromEntries(
|
Ecs.ComponentLikesAndOrBundleLikes = Object.fromEntries(
|
||||||
Object.entries(
|
Object.entries(
|
||||||
await import('./gathered/components.js'),
|
await import('@/gathered/components.js'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {CLIENT_LATENCY} from '@/constants.js';
|
||||||
|
|
||||||
import Packet from '../packet/packet.js';
|
import Packet from '../packet/packet.js';
|
||||||
|
|
||||||
export default class Client {
|
export default class Client {
|
||||||
|
@ -20,6 +22,14 @@ export default class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
send(packet) {
|
send(packet) {
|
||||||
this.transmit(Packet.transmit(packet));
|
if (CLIENT_LATENCY > 0) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.transmit(Packet.transmit(packet));
|
||||||
|
}, CLIENT_LATENCY);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.transmit(Packet.transmit(packet));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import {MOVE_MAP} from '../../constants.js';
|
import {
|
||||||
import Cell from '../../cell.js';
|
MOVE_MAP,
|
||||||
import {System} from '../../ecs/index.js';
|
SERVER_LATENCY,
|
||||||
|
TPS,
|
||||||
|
} from '@/constants.js';
|
||||||
|
import Cell from '@/cell.js';
|
||||||
|
import {System} from '@/ecs/index.js';
|
||||||
import Packet from "../packet/packet.js";
|
import Packet from "../packet/packet.js";
|
||||||
|
|
||||||
const SPEED = 100;
|
const SPEED = 100;
|
||||||
const TPS = 60;
|
|
||||||
|
|
||||||
await import ('../../isomorphinit.js');
|
await import ('@/isomorphinit.js');
|
||||||
|
|
||||||
class MovementSystem extends System {
|
class MovementSystem extends System {
|
||||||
|
|
||||||
|
@ -82,7 +85,14 @@ export default class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
send(connection, packet) {
|
send(connection, packet) {
|
||||||
this.transmit(connection, Packet.transmit(packet));
|
if (SERVER_LATENCY > 0) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.transmit(connection, Packet.transmit(packet));
|
||||||
|
}, SERVER_LATENCY);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.transmit(connection, Packet.transmit(packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {useEffect, useRef, useState} from 'react';
|
import {useEffect, useRef, useState} from 'react';
|
||||||
|
|
||||||
import Dom from '../components/dom.jsx';
|
import Dom from '@/components/dom.jsx';
|
||||||
import {RESOLUTION} from '../constants.js';
|
import {RESOLUTION} from '@/constants.js';
|
||||||
|
|
||||||
function Decorator({children, style}) {
|
function Decorator({children, style}) {
|
||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import {useArgs} from '@storybook/preview-api';
|
import {useArgs} from '@storybook/preview-api';
|
||||||
import {fn} from '@storybook/test';
|
import {fn} from '@storybook/test';
|
||||||
|
|
||||||
import potion from '../assets/potion.png';
|
import potion from '@/assets/potion.png';
|
||||||
import Hotbar from '../components/hotbar.jsx';
|
import Hotbar from '@/components/hotbar.jsx';
|
||||||
import DomDecorator from './dom-decorator.jsx';
|
import DomDecorator from './dom-decorator.jsx';
|
||||||
|
|
||||||
const slots = Array(10).fill({});
|
const slots = Array(10).fill({});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import potion from '../assets/potion.png';
|
import potion from '@/assets/potion.png';
|
||||||
import Slot from '../components/slot.jsx';
|
import Slot from '@/components/slot.jsx';
|
||||||
import DomDecorator from './dom-decorator.jsx';
|
import DomDecorator from './dom-decorator.jsx';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {defineConfig} from 'vite'
|
import {defineConfig} from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
|
import {fileURLToPath} from 'node:url'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
SILPHIUS_WEBSOCKET_PORT = 8080
|
SILPHIUS_WEBSOCKET_PORT = 8080
|
||||||
|
@ -7,6 +8,14 @@ const {
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
resolve: {
|
||||||
|
alias: [
|
||||||
|
{
|
||||||
|
find: '@',
|
||||||
|
replacement: fileURLToPath(new URL('./src', import.meta.url))
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
server: {
|
server: {
|
||||||
host: true,
|
host: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user