Compare commits
1 Commits
online
...
af32320ec4
| Author | SHA1 | Date | |
|---|---|---|---|
| af32320ec4 |
10
README.md
10
README.md
@@ -1,13 +1,9 @@
|
|||||||
# Puzzle'z
|
# Puzzlez
|
||||||
|
|
||||||
Puzzle game
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Play
|
## Play
|
||||||
|
|
||||||
https://shmyga.ru/puzzlez/html5/index.html
|
https://shmyga.ru/puzzlez/html5/index.html
|
||||||
|
|
||||||
## Releases
|
## Packages
|
||||||
|
|
||||||
https://git.shmyga.ru/InfernalGames/puzzlez/releases
|
https://git.shmyga.ru/InfernalGames/-/packages/generic/puzzlez
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 357 KiB |
10
gulpfile.js
10
gulpfile.js
@@ -4,11 +4,8 @@ const Config = require("./config.json");
|
|||||||
const packageInfo = require("./package.json");
|
const packageInfo = require("./package.json");
|
||||||
const { System, Sdk, Haxe, Project } = require("gulp-haxetool");
|
const { System, Sdk, Haxe, Project } = require("gulp-haxetool");
|
||||||
const dateformat = require("dateformat");
|
const dateformat = require("dateformat");
|
||||||
const argv = require("yargs").argv;
|
|
||||||
const publish = require("./tasks/gulp-publish");
|
const publish = require("./tasks/gulp-publish");
|
||||||
|
|
||||||
Project.useRuffle();
|
|
||||||
|
|
||||||
if (packageInfo.haxe) {
|
if (packageInfo.haxe) {
|
||||||
Haxe.VERSION = packageInfo.haxe;
|
Haxe.VERSION = packageInfo.haxe;
|
||||||
}
|
}
|
||||||
@@ -66,9 +63,6 @@ const config = new Project.Config({
|
|||||||
flags: ["proto_debug"],
|
flags: ["proto_debug"],
|
||||||
});
|
});
|
||||||
|
|
||||||
const host = argv.host || "localhost";
|
|
||||||
const port = argv.port || 5000;
|
|
||||||
|
|
||||||
const app = new Project(
|
const app = new Project(
|
||||||
Project.BuildSystem.OPENFL,
|
Project.BuildSystem.OPENFL,
|
||||||
[
|
[
|
||||||
@@ -93,10 +87,6 @@ const app = new Project(
|
|||||||
width: 1280,
|
width: 1280,
|
||||||
height: 768,
|
height: 768,
|
||||||
},
|
},
|
||||||
macros: [
|
|
||||||
`CompilationOption.set('host','${host}')`,
|
|
||||||
`CompilationOption.set('port',${port})`,
|
|
||||||
],
|
|
||||||
flags: ["app"],
|
flags: ["app"],
|
||||||
}),
|
}),
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|||||||
27273
package-lock.json
generated
27273
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
|||||||
"gulp-add": "0.0.2",
|
"gulp-add": "0.0.2",
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
"gulp-cli": "^2.2.0",
|
"gulp-cli": "^2.2.0",
|
||||||
"gulp-haxetool": "^0.2.1",
|
"gulp-haxetool": "^0.1.9",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"haxeDependencies": {
|
"haxeDependencies": {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import hw.app.Const;
|
|||||||
import hw.log.TraceLogger;
|
import hw.log.TraceLogger;
|
||||||
import ru.m.puzzlez.image.ImageSourceBundle;
|
import ru.m.puzzlez.image.ImageSourceBundle;
|
||||||
import ru.m.puzzlez.net.Network;
|
import ru.m.puzzlez.net.Network;
|
||||||
import ru.m.puzzlez.net.NetworkSource;
|
|
||||||
import ru.m.puzzlez.render.part.IPartBuilder;
|
import ru.m.puzzlez.render.part.IPartBuilder;
|
||||||
import ru.m.puzzlez.settings.Settings;
|
import ru.m.puzzlez.settings.Settings;
|
||||||
import ru.m.puzzlez.source.AssetImageSource;
|
import ru.m.puzzlez.source.AssetImageSource;
|
||||||
@@ -28,7 +27,6 @@ class PuzzlezApp {
|
|||||||
IPartBuilder;
|
IPartBuilder;
|
||||||
GameStorage;
|
GameStorage;
|
||||||
Network;
|
Network;
|
||||||
NetworkSource;
|
|
||||||
sourceBundle.register(new AssetImageSource());
|
sourceBundle.register(new AssetImageSource());
|
||||||
sourceBundle.register(new FileImageSource());
|
sourceBundle.register(new FileImageSource());
|
||||||
sourceBundle.register(new PixabayImageSource(CompilationOption.get("PIXABAY_KEY")));
|
sourceBundle.register(new PixabayImageSource(CompilationOption.get("PIXABAY_KEY")));
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import hw.connect.ConnectionFactory;
|
|||||||
import hw.connect.IConnection;
|
import hw.connect.IConnection;
|
||||||
import hw.signal.Signal;
|
import hw.signal.Signal;
|
||||||
import hw.storage.SharedObjectStorage;
|
import hw.storage.SharedObjectStorage;
|
||||||
|
import promhx.Deferred;
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
|
import ru.m.data.DataSource;
|
||||||
import ru.m.puzzlez.proto.core.User;
|
import ru.m.puzzlez.proto.core.User;
|
||||||
import ru.m.puzzlez.proto.event.GameAction;
|
import ru.m.puzzlez.proto.event.GameAction;
|
||||||
import ru.m.puzzlez.proto.event.GameEvent;
|
import ru.m.puzzlez.proto.event.GameEvent;
|
||||||
@@ -21,26 +23,34 @@ import ru.m.puzzlez.proto.pack.NotificationResponse;
|
|||||||
import ru.m.puzzlez.proto.pack.Request;
|
import ru.m.puzzlez.proto.pack.Request;
|
||||||
import ru.m.puzzlez.proto.pack.Response;
|
import ru.m.puzzlez.proto.pack.Response;
|
||||||
|
|
||||||
using ru.m.SignalUtil;
|
class SignalUtil {
|
||||||
|
public static function next<T>(signal:Signal<T>):Promise<T> {
|
||||||
|
var d:Deferred<T> = new Deferred<T>();
|
||||||
|
var receiver:T->Void;
|
||||||
|
receiver = (value:T) -> {
|
||||||
|
signal.disconnect(receiver);
|
||||||
|
d.resolve(value);
|
||||||
|
};
|
||||||
|
signal.connect(receiver);
|
||||||
|
return d.promise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@:provide class Network {
|
@:provide class Network implements DataSource<GameState> {
|
||||||
public var userSignal:Signal<User> = new Signal();
|
public var userSignal:Signal<User> = new Signal();
|
||||||
public var notificationSignal:Signal<NotificationResponse> = new Signal();
|
public var notificationSignal:Signal<NotificationResponse> = new Signal();
|
||||||
public var listSignal:Signal<GameListResponse> = new Signal();
|
public var listSignal:Signal<GameListResponse> = new Signal();
|
||||||
public var joinSignal:Signal<GameState> = new Signal();
|
public var joinSignal:Signal<GameState> = new Signal();
|
||||||
public var gameEventSignal:Signal<GameEvent> = new Signal();
|
public var gameEventSignal:Signal<GameEvent> = new Signal();
|
||||||
|
|
||||||
public var connection:IConnection<Request, Response>;
|
private var connection:IConnection<Request, Response>;
|
||||||
|
|
||||||
private var storage:SharedObjectStorage;
|
private var storage:SharedObjectStorage;
|
||||||
|
|
||||||
private static var USER_KEY = "user";
|
private static var USER_KEY = "user";
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
storage = new SharedObjectStorage("network/2");
|
storage = new SharedObjectStorage("network/2");
|
||||||
var host:String = CompilationOption.get("host");
|
connection = ConnectionFactory.buildClientConnection("127.0.0.1", 5000, Response);
|
||||||
var port:Int = cast(CompilationOption.get("port"), Int);
|
|
||||||
connection = ConnectionFactory.buildClientConnection(host, port, Response);
|
|
||||||
connection.handler.connect(onConnectionChange);
|
connection.handler.connect(onConnectionChange);
|
||||||
connection.receiveHandler.connect(onReceivePacket);
|
connection.receiveHandler.connect(onReceivePacket);
|
||||||
connection.connect().catchError(_ -> {});
|
connection.connect().catchError(_ -> {});
|
||||||
@@ -50,29 +60,23 @@ using ru.m.SignalUtil;
|
|||||||
if (storage.exists(USER_KEY)) {
|
if (storage.exists(USER_KEY)) {
|
||||||
return storage.read(USER_KEY);
|
return storage.read(USER_KEY);
|
||||||
} else {
|
} else {
|
||||||
var uuid = IdUtil.generate();
|
return new User().setName('Anonimus #${IdUtil.generate()}');
|
||||||
return new User().setUuid(uuid).setName('Anonimus #${uuid}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function auth():Promise<User> {
|
public function auth():Promise<User> {
|
||||||
try {
|
connection.send(new Request().setAuth(new AuthRequest().setUser(restoreUser())));
|
||||||
connection.send(new Request().setAuth(new AuthRequest().setUser(restoreUser())));
|
return SignalUtil.next(userSignal);
|
||||||
return userSignal.next();
|
|
||||||
} catch (error:Dynamic) {
|
|
||||||
L.w("network", "auth", error);
|
|
||||||
return Promise.promise(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createGame(preset:GamePreset):Promise<GameState> {
|
public function createGame(preset:GamePreset):Promise<GameState> {
|
||||||
connection.send(new Request().setCreate(new GameCreateRequest().setPreset(preset)));
|
connection.send(new Request().setCreate(new GameCreateRequest().setPreset(preset)));
|
||||||
return joinSignal.next();
|
return SignalUtil.next(joinSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function joinGame(gameId:String):Promise<GameState> {
|
public function joinGame(gameId:String):Promise<GameState> {
|
||||||
connection.send(new Request().setJoin(new GameJoinRequest().setGameId(gameId)));
|
connection.send(new Request().setJoin(new GameJoinRequest().setGameId(gameId)));
|
||||||
return joinSignal.next();
|
return SignalUtil.next(joinSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leaveGame():Void {
|
public function leaveGame():Void {
|
||||||
@@ -110,4 +114,18 @@ using ru.m.SignalUtil;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPage(page:Page):Promise<DataPage<GameState>> {
|
||||||
|
connection.send(new Request().setList(new GameListRequest().setCount(page.count).setPage(page.index)));
|
||||||
|
return SignalUtil.next(listSignal).then((list:GameListResponse) -> ({
|
||||||
|
page: {
|
||||||
|
index: list.page,
|
||||||
|
count: list.count,
|
||||||
|
filter: null,
|
||||||
|
order: null,
|
||||||
|
},
|
||||||
|
total: list.total,
|
||||||
|
data: list.games,
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import ru.m.puzzlez.game.IGame;
|
|||||||
import ru.m.puzzlez.proto.event.GameAction;
|
import ru.m.puzzlez.proto.event.GameAction;
|
||||||
import ru.m.puzzlez.proto.event.GameEvent;
|
import ru.m.puzzlez.proto.event.GameEvent;
|
||||||
import ru.m.puzzlez.proto.game.GameState;
|
import ru.m.puzzlez.proto.game.GameState;
|
||||||
import ru.m.puzzlez.proto.event.gameaction.Action;
|
|
||||||
import ru.m.puzzlez.game.EventUtil;
|
|
||||||
|
|
||||||
class NetworkGame implements IGame {
|
class NetworkGame implements IGame {
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
@@ -21,11 +19,7 @@ class NetworkGame implements IGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function action(action:GameAction):Void {
|
public function action(action:GameAction):Void {
|
||||||
if (action.action == Action.MOVE) {
|
network.sendGameAction(action);
|
||||||
events.emit(EventUtil.action(action));
|
|
||||||
} else {
|
|
||||||
network.sendGameAction(action);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start():Void {
|
public function start():Void {
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package ru.m.puzzlez.net;
|
|
||||||
|
|
||||||
import promhx.Promise;
|
|
||||||
import ru.m.data.DataSource;
|
|
||||||
import ru.m.puzzlez.proto.game.GameState;
|
|
||||||
import ru.m.puzzlez.proto.pack.GameListRequest;
|
|
||||||
import ru.m.puzzlez.proto.pack.GameListResponse;
|
|
||||||
import ru.m.puzzlez.proto.pack.Request;
|
|
||||||
|
|
||||||
using ru.m.SignalUtil;
|
|
||||||
|
|
||||||
@:provide class NetworkSource implements DataSource<GameState> {
|
|
||||||
@:provide private var network:Network;
|
|
||||||
|
|
||||||
public function getPage(page:Page):Promise<DataPage<GameState>> {
|
|
||||||
network.connection.send(new Request().setList(new GameListRequest().setCount(page.count).setPage(page.index)));
|
|
||||||
return network.listSignal.next().then((list:GameListResponse) -> ({
|
|
||||||
page: {
|
|
||||||
index: list.page,
|
|
||||||
count: list.count,
|
|
||||||
filter: null,
|
|
||||||
order: null,
|
|
||||||
},
|
|
||||||
total: list.total,
|
|
||||||
data: list.games,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,6 @@ class NginxImageSource implements ImageSource {
|
|||||||
public var id(default, never):String = "nginx";
|
public var id(default, never):String = "nginx";
|
||||||
|
|
||||||
private var baseUrl:String;
|
private var baseUrl:String;
|
||||||
private var cache:Map<String, Promise<NginxResponse>> = new Map();
|
|
||||||
|
|
||||||
public function new(baseUrl:String) {
|
public function new(baseUrl:String) {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
@@ -37,35 +36,31 @@ class NginxImageSource implements ImageSource {
|
|||||||
|
|
||||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||||
var category = page.filter.get("category");
|
var category = page.filter.get("category");
|
||||||
var url = category != null ? this.baseUrl + category + "/" : this.baseUrl;
|
return new JsonLoader<NginxResponse>().GET(category != null ? this.baseUrl + category + "/" : this.baseUrl)
|
||||||
if (!this.cache.exists(url)) {
|
.then((response:NginxResponse) -> {
|
||||||
this.cache.set(url, new JsonLoader<NginxResponse>().GET(url));
|
var data:Array<ImageId> = [];
|
||||||
}
|
for (item in response) {
|
||||||
return this.cache.get(url).then((response:NginxResponse) -> {
|
if (item.type == NginxResponseItemType.FILE) {
|
||||||
var data:Array<ImageId> = [];
|
var itemId = category != null ? category + "@" + item.name : item.name;
|
||||||
for (item in response) {
|
data.push(new ImageId().setSource(id).setId(itemId));
|
||||||
if (item.type == NginxResponseItemType.FILE) {
|
}
|
||||||
var itemId = category != null ? category + "@" + item.name : item.name;
|
|
||||||
data.push(new ImageId().setSource(id).setId(itemId));
|
|
||||||
}
|
}
|
||||||
}
|
return {
|
||||||
data = data.slice(page.index * page.count, (page.index + 1) * page.count);
|
page: page,
|
||||||
return {
|
data: data,
|
||||||
page: page,
|
total: response.length,
|
||||||
data: data,
|
}
|
||||||
total: response.length,
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(id:String, thumb:Bool = false):Promise<ImageValue> {
|
public function load(id:String, thumb:Bool = false):Promise<ImageValue> {
|
||||||
var url = this.baseUrl + StringTools.replace(id, "@", "/");
|
var url = this.baseUrl + StringTools.replace(id, "@", "/");
|
||||||
// TODO: default size by screen width?
|
if (thumb) {
|
||||||
var width = thumb ? 360 : 1920;
|
var parts = url.split(".");
|
||||||
var parts = url.split(".");
|
var index = parts.length - 2;
|
||||||
var index = parts.length - 2;
|
parts[index] = parts[index] + "-thumbnail";
|
||||||
parts[index] = parts[index] + '-w${width}';
|
url = parts.join(".");
|
||||||
url = parts.join(".");
|
}
|
||||||
return Promise.promise(ImageValue.URL(url));
|
return Promise.promise(ImageValue.URL(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ru.m.puzzlez.view;
|
package ru.m.puzzlez.view;
|
||||||
|
|
||||||
|
import ru.m.puzzlez.net.Network;
|
||||||
import hw.view.data.DataView;
|
import hw.view.data.DataView;
|
||||||
import hw.view.form.ButtonView;
|
import hw.view.form.ButtonView;
|
||||||
import hw.view.frame.FrameSwitcher;
|
import hw.view.frame.FrameSwitcher;
|
||||||
import hw.view.frame.FrameView;
|
import hw.view.frame.FrameView;
|
||||||
import ru.m.puzzlez.FileUtil;
|
import ru.m.puzzlez.FileUtil;
|
||||||
import ru.m.puzzlez.image.ImageSourceBundle;
|
import ru.m.puzzlez.image.ImageSourceBundle;
|
||||||
import ru.m.puzzlez.net.NetworkSource;
|
|
||||||
import ru.m.puzzlez.proto.game.GameStatus;
|
import ru.m.puzzlez.proto.game.GameStatus;
|
||||||
import ru.m.puzzlez.storage.FileStorage;
|
import ru.m.puzzlez.storage.FileStorage;
|
||||||
import ru.m.puzzlez.storage.GameStorage;
|
import ru.m.puzzlez.storage.GameStorage;
|
||||||
@@ -29,7 +29,7 @@ import ru.m.update.Updater;
|
|||||||
@:provide var fileStorage:FileStorage;
|
@:provide var fileStorage:FileStorage;
|
||||||
@:provide var gameStorage:GameStorage;
|
@:provide var gameStorage:GameStorage;
|
||||||
@:provide var sourceBundle:ImageSourceBundle;
|
@:provide var sourceBundle:ImageSourceBundle;
|
||||||
@:provide var networkSource:NetworkSource;
|
@:provide var network:Network;
|
||||||
|
|
||||||
private var fileSource:ImageListConfig = {title: "Files", sourceId: "file"};
|
private var fileSource:ImageListConfig = {title: "Files", sourceId: "file"};
|
||||||
private var startedGames:GameListConfig = {
|
private var startedGames:GameListConfig = {
|
||||||
@@ -44,7 +44,7 @@ import ru.m.update.Updater;
|
|||||||
};
|
};
|
||||||
private var networkGames:GameListConfig = {
|
private var networkGames:GameListConfig = {
|
||||||
title: "Network",
|
title: "Network",
|
||||||
source: networkSource
|
source: network
|
||||||
};
|
};
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package ru.m;
|
|
||||||
|
|
||||||
import hw.signal.Signal;
|
|
||||||
import promhx.Deferred;
|
|
||||||
import promhx.Promise;
|
|
||||||
|
|
||||||
class SignalUtil {
|
|
||||||
public static function next<T>(signal:Signal<T>):Promise<T> {
|
|
||||||
var d:Deferred<T> = new Deferred<T>();
|
|
||||||
var receiver:T->Void;
|
|
||||||
receiver = (value:T) -> {
|
|
||||||
signal.disconnect(receiver);
|
|
||||||
d.resolve(value);
|
|
||||||
};
|
|
||||||
signal.connect(receiver);
|
|
||||||
return d.promise();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user