Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@@ -7,7 +7,7 @@ jobs:
|
||||
build:
|
||||
name: Linux Build
|
||||
permissions: write-all
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Pulling the source
|
||||
uses: actions/checkout@v2
|
||||
|
||||
+410
@@ -0,0 +1,410 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Xml node types.
|
||||
|
||||
@see https://haxe.org/manual/std-Xml.html
|
||||
**/
|
||||
enum abstract XmlType(Int) {
|
||||
/**
|
||||
Represents an XML element type.
|
||||
**/
|
||||
var Element = 0;
|
||||
|
||||
/**
|
||||
Represents XML parsed character data type.
|
||||
**/
|
||||
var PCData = 1;
|
||||
|
||||
/**
|
||||
Represents XML character data type.
|
||||
**/
|
||||
var CData = 2;
|
||||
|
||||
/**
|
||||
Represents an XML comment type.
|
||||
**/
|
||||
var Comment = 3;
|
||||
|
||||
/**
|
||||
Represents an XML doctype element type.
|
||||
**/
|
||||
var DocType = 4;
|
||||
|
||||
/**
|
||||
Represents an XML processing instruction type.
|
||||
**/
|
||||
var ProcessingInstruction = 5;
|
||||
|
||||
/**
|
||||
Represents an XML document type.
|
||||
**/
|
||||
var Document = 6;
|
||||
|
||||
public function toString():String {
|
||||
return switch (cast this : XmlType) {
|
||||
case Element: "Element";
|
||||
case PCData: "PCData";
|
||||
case CData: "CData";
|
||||
case Comment: "Comment";
|
||||
case DocType: "DocType";
|
||||
case ProcessingInstruction: "ProcessingInstruction";
|
||||
case Document: "Document";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Cross-platform Xml API.
|
||||
|
||||
@see https://haxe.org/manual/std-Xml.html
|
||||
**/
|
||||
class Xml {
|
||||
/**
|
||||
XML element type.
|
||||
**/
|
||||
static public var Element(default, never) = XmlType.Element;
|
||||
|
||||
/**
|
||||
XML parsed character data type.
|
||||
**/
|
||||
static public var PCData(default, never) = XmlType.PCData;
|
||||
|
||||
/**
|
||||
XML character data type.
|
||||
**/
|
||||
static public var CData(default, never) = XmlType.CData;
|
||||
|
||||
/**
|
||||
XML comment type.
|
||||
**/
|
||||
static public var Comment(default, never) = XmlType.Comment;
|
||||
|
||||
/**
|
||||
XML doctype element type.
|
||||
**/
|
||||
static public var DocType(default, never) = XmlType.DocType;
|
||||
|
||||
/**
|
||||
XML processing instruction type.
|
||||
**/
|
||||
static public var ProcessingInstruction(default, never) = XmlType.ProcessingInstruction;
|
||||
|
||||
/**
|
||||
XML document type.
|
||||
**/
|
||||
static public var Document(default, never) = XmlType.Document;
|
||||
|
||||
/**
|
||||
Parses the String into an Xml document.
|
||||
**/
|
||||
static public function parse(str:String):Xml {
|
||||
return haxe.xml.Parser.parse(str);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the type of the Xml Node. This should be used before
|
||||
accessing other functions since some might raise an exception
|
||||
if the node type is not correct.
|
||||
**/
|
||||
public var nodeType(default, null):XmlType;
|
||||
|
||||
/**
|
||||
Returns the node name of an Element.
|
||||
**/
|
||||
@:isVar public var nodeName(get, set):String;
|
||||
|
||||
/**
|
||||
Returns the node value. Only works if the Xml node is not an Element or a Document.
|
||||
**/
|
||||
@:isVar public var nodeValue(get, set):String;
|
||||
|
||||
/**
|
||||
Returns the parent object in the Xml hierarchy.
|
||||
The parent can be `null`, an Element or a Document.
|
||||
**/
|
||||
public var parent(default, null):Xml;
|
||||
|
||||
var children:Array<Xml>;
|
||||
var attributeMap:Map<String, String>;
|
||||
|
||||
public var attributeOrder:Array<String>;
|
||||
|
||||
#if !cppia inline #end function get_nodeName() {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
#if !cppia inline #end function set_nodeName(v) {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
return this.nodeName = v;
|
||||
}
|
||||
|
||||
#if !cppia inline #end function get_nodeValue() {
|
||||
if (nodeType == Document || nodeType == Element) {
|
||||
throw 'Bad node type, unexpected $nodeType';
|
||||
}
|
||||
return nodeValue;
|
||||
}
|
||||
|
||||
#if !cppia inline #end function set_nodeValue(v) {
|
||||
if (nodeType == Document || nodeType == Element) {
|
||||
throw 'Bad node type, unexpected $nodeType';
|
||||
}
|
||||
return this.nodeValue = v;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createElement(name:String):Xml {
|
||||
var xml = new Xml(Element);
|
||||
xml.nodeName = name;
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createPCData(data:String):Xml {
|
||||
var xml = new Xml(PCData);
|
||||
xml.nodeValue = data;
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createCData(data:String):Xml {
|
||||
var xml = new Xml(CData);
|
||||
xml.nodeValue = data;
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createComment(data:String):Xml {
|
||||
var xml = new Xml(Comment);
|
||||
xml.nodeValue = data;
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createDocType(data:String):Xml {
|
||||
var xml = new Xml(DocType);
|
||||
xml.nodeValue = data;
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createProcessingInstruction(data:String):Xml {
|
||||
var xml = new Xml(ProcessingInstruction);
|
||||
xml.nodeValue = data;
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a node of the given type.
|
||||
**/
|
||||
static public function createDocument():Xml {
|
||||
return new Xml(Document);
|
||||
}
|
||||
|
||||
/**
|
||||
Get the given attribute of an Element node. Returns `null` if not found.
|
||||
Attributes are case-sensitive.
|
||||
**/
|
||||
public function get(att:String):String {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
return attributeMap[att];
|
||||
}
|
||||
|
||||
/**
|
||||
Set the given attribute value for an Element node.
|
||||
Attributes are case-sensitive.
|
||||
**/
|
||||
public function set(att:String, value:String):Void {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
attributeMap.set(att, value);
|
||||
}
|
||||
|
||||
/**
|
||||
Removes an attribute for an Element node.
|
||||
Attributes are case-sensitive.
|
||||
**/
|
||||
public function remove(att:String):Void {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
attributeMap.remove(att);
|
||||
}
|
||||
|
||||
/**
|
||||
Tells if the Element node has a given attribute.
|
||||
Attributes are case-sensitive.
|
||||
**/
|
||||
public function exists(att:String):Bool {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
return attributeMap.exists(att);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an `Iterator` on all the attribute names.
|
||||
**/
|
||||
public function attributes():Iterator<String> {
|
||||
if (nodeType != Element) {
|
||||
throw 'Bad node type, expected Element but found $nodeType';
|
||||
}
|
||||
return attributeMap.keys();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an iterator of all child nodes.
|
||||
Only works if the current node is an Element or a Document.
|
||||
**/
|
||||
public #if !cppia inline #end function iterator():Iterator<Xml> {
|
||||
ensureElementType();
|
||||
return children.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an iterator of all child nodes which are Elements.
|
||||
Only works if the current node is an Element or a Document.
|
||||
**/
|
||||
public function elements():Iterator<Xml> {
|
||||
ensureElementType();
|
||||
var ret = [for (child in children) if (child.nodeType == Element) child];
|
||||
return ret.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an iterator of all child nodes which are Elements with the given nodeName.
|
||||
Only works if the current node is an Element or a Document.
|
||||
**/
|
||||
public function elementsNamed(name:String):Iterator<Xml> {
|
||||
ensureElementType();
|
||||
var ret = [
|
||||
for (child in children)
|
||||
if (child.nodeType == Element && child.nodeName == name) child
|
||||
];
|
||||
return ret.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the first child node.
|
||||
**/
|
||||
public #if !cppia inline #end function firstChild():Xml {
|
||||
ensureElementType();
|
||||
return children[0];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the first child node which is an Element.
|
||||
**/
|
||||
public function firstElement():Xml {
|
||||
ensureElementType();
|
||||
for (child in children) {
|
||||
if (child.nodeType == Element) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a child node to the Document or Element.
|
||||
A child node can only be inside one given parent node, which is indicated by the `parent` property.
|
||||
If the child is already inside this Document or Element, it will be moved to the last position among the Document or Element's children.
|
||||
If the child node was previously inside a different node, it will be moved to this Document or Element.
|
||||
**/
|
||||
public function addChild(x:Xml):Void {
|
||||
ensureElementType();
|
||||
if (x.parent != null) {
|
||||
x.parent.removeChild(x);
|
||||
}
|
||||
children.push(x);
|
||||
x.parent = this;
|
||||
}
|
||||
|
||||
/**
|
||||
Removes a child from the Document or Element.
|
||||
Returns true if the child was successfuly removed.
|
||||
**/
|
||||
public function removeChild(x:Xml):Bool {
|
||||
ensureElementType();
|
||||
if (children.remove(x)) {
|
||||
x.parent = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Inserts a child at the given position among the other childs.
|
||||
A child node can only be inside one given parent node, which is indicated by the [parent] property.
|
||||
If the child is already inside this Document or Element, it will be moved to the new position among the Document or Element's children.
|
||||
If the child node was previously inside a different node, it will be moved to this Document or Element.
|
||||
**/
|
||||
public function insertChild(x:Xml, pos:Int):Void {
|
||||
ensureElementType();
|
||||
if (x.parent != null) {
|
||||
x.parent.children.remove(x);
|
||||
}
|
||||
children.insert(pos, x);
|
||||
x.parent = this;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a String representation of the Xml node.
|
||||
**/
|
||||
public #if !cppia inline #end function toString():String {
|
||||
return haxe.xml.Printer.print(this);
|
||||
}
|
||||
|
||||
function new(nodeType:XmlType) {
|
||||
this.nodeType = nodeType;
|
||||
children = [];
|
||||
attributeMap = new Map();
|
||||
}
|
||||
|
||||
inline function ensureElementType() {
|
||||
if (nodeType != Document && nodeType != Element) {
|
||||
throw 'Bad node type, expected Element or Document but found $nodeType';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class Conductor
|
||||
// update conductor
|
||||
songPosition = lastSongPos;
|
||||
} else {
|
||||
songPosition = songPosition + songOffset + elapsed * 1000;
|
||||
songPosition += songOffset + elapsed * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,6 @@ class MainState extends FlxState {
|
||||
betaWarningShown = true;
|
||||
}
|
||||
|
||||
CoolUtil.safeSetAttribute('./.temp/', HIDDEN);
|
||||
CoolUtil.safeAddAttributes('./.temp/', NativeAPI.FileAttribute.HIDDEN);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,21 @@ package funkin.backend.utils;
|
||||
#if sys
|
||||
import sys.FileSystem;
|
||||
#end
|
||||
import flixel.text.FlxText;
|
||||
import funkin.backend.utils.XMLUtil.TextFormat;
|
||||
import flixel.util.typeLimit.OneOfTwo;
|
||||
import flixel.util.typeLimit.OneOfThree;
|
||||
import flixel.tweens.FlxTween;
|
||||
import flixel.system.frontEnds.SoundFrontEnd;
|
||||
import flixel.sound.FlxSound;
|
||||
import funkin.backend.system.Conductor;
|
||||
import flixel.sound.FlxSoundGroup;
|
||||
import haxe.Json;
|
||||
import haxe.io.Path;
|
||||
import haxe.io.Bytes;
|
||||
import haxe.xml.Access;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
import lime.utils.Assets;
|
||||
import flixel.animation.FlxAnimation;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
import flixel.sound.FlxSound;
|
||||
@@ -99,18 +114,66 @@ class CoolUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an attribute to a file or a folder adding eventual missing folders in the path
|
||||
* (WARNING: Only works on `windows`. On other platforms the return code it's always going to be `0` but still creates eventual missing folders if the platforms allows it to).
|
||||
* Gets file attributes from a file or a folder adding eventual missing folders in the path
|
||||
* (WARNING: Only works on `windows` for now. On other platforms the attributes' value it's always going to be `0` -thanks to the wrapper you can also use `isNothing` for checking- but still creates eventual missing folders if the platforms allows it to).
|
||||
* @param path Path to the file or folder
|
||||
* @param attrib The attribute to set (WARNING: There are some non settable attributes, such as the `COMPRESSED` one)
|
||||
* @param useAbsol If it should use the absolute path (By default it's `true` but if it's `false` you can use files outside from this program's directory for example)
|
||||
* @return The result code: 0 means that it failed setting
|
||||
* @return The attributes through the `FileAttributeWrapper`
|
||||
*/
|
||||
@:noUsing public static inline function safeSetAttribute(path:String, attrib:NativeAPI.FileAttribute, useAbsol:Bool = true) {
|
||||
@:noUsing public static inline function safeGetAttributes(path:String, useAbsol:Bool = true):FileAttributeWrapper {
|
||||
addMissingFolders(Path.directory(path));
|
||||
|
||||
var result = NativeAPI.setFileAttribute(path, attrib, useAbsol);
|
||||
if(result == 0) Logs.trace('Failed to set attribute to $path with a code of: $result', WARNING);
|
||||
var result = NativeAPI.getFileAttributes(path, useAbsol);
|
||||
if(result.isNothing) Logs.trace('The file where it has been tried to get the attributes from, might be corrupted or inexistent (code: ${result.getValue()})', WARNING);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets file attributes to a file or a folder adding eventual missing folders in the path
|
||||
* (WARNING: Only works on `windows` for now. On other platforms the return code it's always going to be `0` but still creates eventual missing folders if the platforms allows it to).
|
||||
* @param path Path to the file or folder
|
||||
* @param attrib The attribute(s) to set (WARNING: There are some non settable attributes, such as the `COMPRESSED` one)
|
||||
* @param useAbsol If it should use the absolute path (By default it's `true` but if it's `false` you can use files outside from this program's directory for example)
|
||||
* @return The result code: `0` means that it failed setting
|
||||
*/
|
||||
@:noUsing public static inline function safeSetAttributes(path:String, attrib:OneOfThree<NativeAPI.FileAttribute, FileAttributeWrapper, Int>, useAbsol:Bool = true):Int {
|
||||
// yes, i'm aware that FileAttribute is also an Int so need to include it too, but at least like this we don't have to make cast sometimes while passing the arguments - Nex
|
||||
addMissingFolders(Path.directory(path));
|
||||
|
||||
var result = NativeAPI.setFileAttributes(path, attrib, useAbsol);
|
||||
if(result == 0) Logs.trace('Failed to set attributes to $path with a code of: $result', WARNING);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds one (or more) file attributes to a file or a folder adding eventual missing folders in the path
|
||||
* (WARNING: Only works on `windows` for now. On other platforms the return code it's always going to be `0` but still creates eventual missing folders if the platforms allows it to).
|
||||
* @param path Path to the file or folder
|
||||
* @param attrib The attribute(s) to add (WARNING: There are some non settable attributes, such as the `COMPRESSED` one)
|
||||
* @param useAbsol If it should use the absolute path (By default it's `true` but if it's `false` you can use files outside from this program's directory for example)
|
||||
* @return The result code: `0` means that it failed setting
|
||||
*/
|
||||
@:noUsing public static inline function safeAddAttributes(path:String, attrib:OneOfTwo<NativeAPI.FileAttribute, Int>, useAbsol:Bool = true):Int {
|
||||
addMissingFolders(Path.directory(path));
|
||||
|
||||
var result = NativeAPI.addFileAttributes(path, attrib, useAbsol);
|
||||
if(result == 0) Logs.trace('Failed to add attributes to $path with a code of: $result', WARNING);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes one (or more) file attributes to a file or a folder adding eventual missing folders in the path
|
||||
* (WARNING: Only works on `windows` for now. On other platforms the return code it's always going to be `0` but still creates eventual missing folders if the platforms allows it to).
|
||||
* @param path Path to the file or folder
|
||||
* @param attrib The attribute(s) to remove (WARNING: There are some non settable attributes, such as the `COMPRESSED` one)
|
||||
* @param useAbsol If it should use the absolute path (By default it's `true` but if it's `false` you can use files outside from this program's directory for example)
|
||||
* @return The result code: `0` means that it failed setting
|
||||
*/
|
||||
@:noUsing public static inline function safeRemoveAttributes(path:String, attrib:OneOfTwo<NativeAPI.FileAttribute, Int>, useAbsol:Bool = true):Int {
|
||||
addMissingFolders(Path.directory(path));
|
||||
|
||||
var result = NativeAPI.removeFileAttributes(path, attrib, useAbsol);
|
||||
if(result == 0) Logs.trace('Failed to remove attributes to $path with a code of: $result', WARNING);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -748,6 +811,16 @@ class CoolUtil
|
||||
return array.indexOf(element) != -1;
|
||||
}
|
||||
#end
|
||||
|
||||
/*
|
||||
* Returns the filename of a path, without the extension.
|
||||
* @param path Path to get the filename from
|
||||
* @return Filename
|
||||
*/
|
||||
@:noUsing public static inline function getFilename(file:String) {
|
||||
var file = new haxe.io.Path(file);
|
||||
return file.file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
package funkin.backend.utils;
|
||||
|
||||
import flixel.util.FlxStringUtil;
|
||||
import funkin.backend.utils.NativeAPI.FileAttribute;
|
||||
|
||||
/**
|
||||
* Currently only for Windows, but planned to work on other platforms later.
|
||||
*/
|
||||
class FileAttributeWrapper
|
||||
{
|
||||
private var flags:Int;
|
||||
inline public function getValue():Int
|
||||
{
|
||||
return flags;
|
||||
}
|
||||
|
||||
public function new(flags:Int)
|
||||
{
|
||||
this.flags = flags == -1 ? 0 : flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the attributes.
|
||||
*/
|
||||
inline public function toString():String
|
||||
{
|
||||
return FlxStringUtil.getDebugString([
|
||||
for (field in Reflect.fields(this))
|
||||
{
|
||||
LabelValuePair.weak(field, Reflect.getProperty(this, field));
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
// Settables
|
||||
public var isArchived(get, set):Bool;
|
||||
private function get_isArchived():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.ARCHIVE) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isArchived(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.ARCHIVE;
|
||||
else
|
||||
flags &= ~FileAttribute.ARCHIVE;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isHidden(get, set):Bool;
|
||||
private function get_isHidden():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.HIDDEN) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isHidden(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.HIDDEN;
|
||||
else
|
||||
flags &= ~FileAttribute.HIDDEN;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isNormal(get, set):Bool;
|
||||
private function get_isNormal():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.NORMAL) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isNormal(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.NORMAL;
|
||||
else
|
||||
flags &= ~FileAttribute.NORMAL;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isNotContentIndexed(get, set):Bool;
|
||||
private function get_isNotContentIndexed():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.NOT_CONTENT_INDEXED) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isNotContentIndexed(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.NOT_CONTENT_INDEXED;
|
||||
else
|
||||
flags &= ~FileAttribute.NOT_CONTENT_INDEXED;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isOffline(get, set):Bool;
|
||||
private function get_isOffline():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.OFFLINE) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isOffline(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.OFFLINE;
|
||||
else
|
||||
flags &= ~FileAttribute.OFFLINE;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isReadOnly(get, set):Bool;
|
||||
private function get_isReadOnly():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.READONLY) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isReadOnly(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.READONLY;
|
||||
else
|
||||
flags &= ~FileAttribute.READONLY;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isSystem(get, set):Bool;
|
||||
private function get_isSystem():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.SYSTEM) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isSystem(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.SYSTEM;
|
||||
else
|
||||
flags &= ~FileAttribute.SYSTEM;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isTemporary(get, set):Bool;
|
||||
private function get_isTemporary():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.TEMPORARY) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
private function set_isTemporary(value:Bool):Bool
|
||||
{
|
||||
#if windows
|
||||
if (value)
|
||||
flags |= FileAttribute.TEMPORARY;
|
||||
else
|
||||
flags &= ~FileAttribute.TEMPORARY;
|
||||
return value;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
// Non Settables
|
||||
public var isCompressed(get, never):Bool;
|
||||
private function get_isCompressed():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.COMPRESSED) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isDevice(get, never):Bool;
|
||||
private function get_isDevice():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.DEVICE) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isDirectory(get, never):Bool;
|
||||
private function get_isDirectory():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.DIRECTORY) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isEncrypted(get, never):Bool;
|
||||
private function get_isEncrypted():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.ENCRYPTED) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isReparsePoint(get, never):Bool;
|
||||
private function get_isReparsePoint():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.REPARSE_POINT) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
public var isSparseFile(get, never):Bool;
|
||||
private function get_isSparseFile():Bool
|
||||
{
|
||||
#if windows
|
||||
return (flags & FileAttribute.SPARSE_FILE) != 0;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
|
||||
// For checking
|
||||
public var isNothing(get, never):Bool;
|
||||
private function get_isNothing():Bool
|
||||
{
|
||||
#if windows
|
||||
return flags == 0;
|
||||
#else
|
||||
return true;
|
||||
#end
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package funkin.backend.utils;
|
||||
|
||||
import funkin.backend.utils.native.*;
|
||||
import flixel.util.typeLimit.OneOfTwo;
|
||||
import flixel.util.typeLimit.OneOfThree;
|
||||
|
||||
/**
|
||||
* Class for functions that talk to a lower level than haxe, such as message boxes, and more.
|
||||
@@ -30,24 +32,53 @@ class NativeAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the specified file's (or folder) attribute.
|
||||
* Gets the specified file's (or folder) attributes.
|
||||
*/
|
||||
public static function getFileAttribute(path:String, useAbsol:Bool = true):FileAttribute {
|
||||
public static function getFileAttributesRaw(path:String, useAbsol:Bool = true):Int {
|
||||
#if windows
|
||||
if(useAbsol) path = sys.FileSystem.absolutePath(path);
|
||||
return Windows.getFileAttribute(path);
|
||||
return Windows.getFileAttributes(path);
|
||||
#else
|
||||
return NORMAL;
|
||||
return -1;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified file's (or folder) attribute. If it fails, the return value is `0`.
|
||||
* Gets the specified file's (or folder) attributes and passes it to `FileAttributeWrapper`.
|
||||
*/
|
||||
public static function setFileAttribute(path:String, attrib:FileAttribute, useAbsol:Bool = true):Int {
|
||||
public static function getFileAttributes(path:String, useAbsol:Bool = true):FileAttributeWrapper {
|
||||
return new FileAttributeWrapper(getFileAttributesRaw(path, useAbsol));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified file's (or folder) attributes. If it fails, the return value is `0`.
|
||||
*/
|
||||
public static function setFileAttributes(path:String, attrib:OneOfThree<NativeAPI.FileAttribute, FileAttributeWrapper, Int>, useAbsol:Bool = true):Int {
|
||||
#if windows
|
||||
if(useAbsol) path = sys.FileSystem.absolutePath(path);
|
||||
return Windows.setFileAttribute(path, attrib);
|
||||
return Windows.setFileAttributes(path, attrib is FileAttributeWrapper ? cast(attrib, FileAttributeWrapper).getValue() : cast(attrib, Int));
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes from the specified file's (or folder) one (or more) specific attribute.
|
||||
*/
|
||||
public static function addFileAttributes(path:String, attrib:OneOfTwo<NativeAPI.FileAttribute, Int>, useAbsol:Bool = true):Int {
|
||||
#if windows
|
||||
return setFileAttributes(path, getFileAttributesRaw(path, useAbsol) | cast(attrib, Int), useAbsol);
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes from the specified file's (or folder) one (or more) specific attribute.
|
||||
*/
|
||||
public static function removeFileAttributes(path:String, attrib:OneOfTwo<NativeAPI.FileAttribute, Int>, useAbsol:Bool = true):Int {
|
||||
#if windows
|
||||
return setFileAttributes(path, getFileAttributesRaw(path, useAbsol) & ~cast(attrib, Int), useAbsol);
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
@@ -137,7 +168,7 @@ class NativeAPI {
|
||||
}
|
||||
}
|
||||
|
||||
enum abstract FileAttribute(Int) {
|
||||
enum abstract FileAttribute(Int) from Int to Int {
|
||||
// Settables
|
||||
var ARCHIVE = 0x20;
|
||||
var HIDDEN = 0x2;
|
||||
|
||||
@@ -157,7 +157,7 @@ class Windows {
|
||||
@:functionCode('
|
||||
return GetFileAttributes(path);
|
||||
')
|
||||
public static function getFileAttribute(path:String):FileAttribute
|
||||
public static function getFileAttributes(path:String):FileAttribute
|
||||
{
|
||||
return NORMAL;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class Windows {
|
||||
@:functionCode('
|
||||
return SetFileAttributes(path, attrib);
|
||||
')
|
||||
public static function setFileAttribute(path:String, attrib:FileAttribute):Int
|
||||
public static function setFileAttributes(path:String, attrib:FileAttribute):Int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -348,10 +348,6 @@ class CharacterEditor extends UIState {
|
||||
}
|
||||
|
||||
function buildCharacter():String {
|
||||
if (character.isPlayer != character.playerOffsets) {
|
||||
character.switchOffset('singLEFT', 'singRIGHT');
|
||||
character.switchOffset('singLEFTmiss', 'singRIGHTmiss');
|
||||
}
|
||||
var charXML:Xml = character.buildXML([
|
||||
for (button in characterAnimsWindow.buttons.members)
|
||||
button.anim
|
||||
@@ -588,6 +584,12 @@ class CharacterEditor extends UIState {
|
||||
function changeOffset(anim:String, change:FlxPoint, addtoUndo:Bool = true) {
|
||||
if (character.getNameList().length == 0) return;
|
||||
|
||||
var animData = character.animDatas.get(anim);
|
||||
if (animData != null) {
|
||||
animData.x += change.x;
|
||||
animData.y += change.y;
|
||||
}
|
||||
|
||||
character.animOffsets.set(anim, character.getAnimOffset(anim) + change);
|
||||
for (i in characterAnimsWindow.buttons.members)
|
||||
if (i.anim == anim)
|
||||
|
||||
@@ -119,7 +119,7 @@ class CharacterInfoScreen extends UISubstateWindow {
|
||||
add(isPlayerCheckbox);
|
||||
addLabelOn(isPlayerCheckbox, "Is Player");
|
||||
|
||||
isGFCheckbox = new UICheckbox(isPlayerCheckbox.x + 128, positionXStepper.y + 10 + 32 + 28, "isGF", character.isGF);
|
||||
isGFCheckbox = new UICheckbox(isPlayerCheckbox.x + 128, positionXStepper.y + 10 + 32 + 28, "isGF", false);
|
||||
add(isGFCheckbox);
|
||||
addLabelOn(isGFCheckbox, "Is GF");
|
||||
|
||||
@@ -168,7 +168,6 @@ class CharacterInfoScreen extends UISubstateWindow {
|
||||
|
||||
var xml = Xml.createElement("character");
|
||||
xml.set("isPlayer", isPlayerCheckbox.checked ? "true" : "false");
|
||||
xml.set("isGF", isGFCheckbox.checked ? "true" : "false");
|
||||
xml.set("x", Std.string(positionXStepper.value));
|
||||
xml.set("y", Std.string(positionYStepper.value));
|
||||
xml.set("gameOverChar", gameOverCharTextBox.label.text);
|
||||
|
||||
+210
-284
@@ -1,5 +1,6 @@
|
||||
package funkin.game;
|
||||
|
||||
import flixel.util.typeLimit.OneOfTwo;
|
||||
import flixel.graphics.frames.FlxFrame;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.math.FlxRect;
|
||||
@@ -26,15 +27,8 @@ using StringTools;
|
||||
@:allow(funkin.desktop.editors.CharacterEditor)
|
||||
@:allow(funkin.game.StrumLine)
|
||||
@:allow(funkin.game.PlayState)
|
||||
class Character extends FunkinSprite implements IBeatReceiver implements IOffsetCompatible
|
||||
{
|
||||
private var __stunnedTime:Float = 0;
|
||||
private var __lockAnimThisFrame:Bool = false;
|
||||
|
||||
public var stunned(default, set):Bool = false;
|
||||
|
||||
class Character extends FunkinSprite implements IBeatReceiver implements IOffsetCompatible {
|
||||
public var isPlayer:Bool = false;
|
||||
public var isGF:Bool = false;
|
||||
public var curCharacter:String = 'bf';
|
||||
public var sprite:String = 'bf';
|
||||
|
||||
@@ -45,30 +39,21 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
|
||||
public var icon:String = null;
|
||||
public var iconColor:Null<FlxColor> = null;
|
||||
public var gameOverCharacter:String = "bf-dead";
|
||||
public var gameOverCharacter:String = Character.FALLBACK_DEAD_CHARACTER;
|
||||
|
||||
public var cameraOffset:FlxPoint = new FlxPoint(0, 0);
|
||||
public var globalOffset:FlxPoint = new FlxPoint(0, 0);
|
||||
public var cameraOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||
public var globalOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||
|
||||
public var script:Script;
|
||||
public var xml:Access;
|
||||
|
||||
public var shadowFrame:CharacterShadowFrame;
|
||||
public var idleSuffix:String = "";
|
||||
public var stunned(default, set):Bool = false;
|
||||
|
||||
public var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; // Not making these inline so theyre editable through scripts! - Nex
|
||||
@:noCompletion var __stunnedTime:Float = 0;
|
||||
@:noCompletion var __lockAnimThisFrame:Bool = false;
|
||||
|
||||
public inline function getCameraPosition()
|
||||
{
|
||||
var midpoint = getMidpoint();
|
||||
var event = EventManager.get(PointEvent).recycle(
|
||||
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
|
||||
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
|
||||
script.call("onGetCamPos", [event]);
|
||||
midpoint.put();
|
||||
// this event cannot be cancelled
|
||||
return new FlxPoint(event.x, event.y);
|
||||
}
|
||||
@:noCompletion var __switchAnims:Bool = true;
|
||||
|
||||
public inline function getSingAnim(direction:Int, suffix:String = ""):String
|
||||
{
|
||||
@@ -94,114 +79,69 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
|
||||
}
|
||||
|
||||
public function new(x:Float, y:Float, ?character:String = "bf", isPlayer:Bool = false, switchAnims:Bool = true)
|
||||
public function new(x:Float, y:Float, ?character:String = "bf", isPlayer:Bool = false, switchAnims:Bool = true, disableScripts:Bool = false)
|
||||
{
|
||||
super(x, y);
|
||||
|
||||
animOffsets = new Map<String, FlxPoint>();
|
||||
curCharacter = character;
|
||||
this.isPlayer = isPlayer;
|
||||
__switchAnims = switchAnims;
|
||||
|
||||
antialiasing = true;
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (curCharacter)
|
||||
{
|
||||
// case 'your-char': // To hardcode characters
|
||||
default:
|
||||
// load xml
|
||||
var xmlPath = Paths.xml('characters/$curCharacter');
|
||||
if (!Assets.exists(xmlPath))
|
||||
{
|
||||
curCharacter = "bf";
|
||||
continue;
|
||||
}
|
||||
xml = getXMLFromCharName(this);
|
||||
|
||||
if(!disableScripts)
|
||||
script = Script.create(Paths.script(Path.withoutExtension(Paths.xml('characters/$curCharacter')), null, true));
|
||||
else
|
||||
script = new DummyScript(curCharacter);
|
||||
script.setParent(this);
|
||||
script.load();
|
||||
|
||||
buildCharacter(xml);
|
||||
script.call("create");
|
||||
|
||||
var plainXML = Assets.getText(xmlPath);
|
||||
try
|
||||
{
|
||||
var charXML = Xml.parse(plainXML).firstElement();
|
||||
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
|
||||
xml = new Access(charXML);
|
||||
} catch (e) {
|
||||
Logs.trace('Error while loading character ${curCharacter}: ${e}', ERROR);
|
||||
curCharacter = "bf";
|
||||
continue;
|
||||
}
|
||||
// Loads the script
|
||||
script = Script.create(Paths.script(Path.withoutExtension(xmlPath), null, true));
|
||||
script.setParent(this);
|
||||
script.load();
|
||||
applyXML(xml);
|
||||
script.call("create");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (script == null)
|
||||
script = new DummyScript(curCharacter);
|
||||
|
||||
/**
|
||||
NON CONVERTED CHARACTERS - DO NOT REMOVE
|
||||
**/
|
||||
// case 'bf-pixel-dead':
|
||||
// frames = Paths.getSparrowAtlas('weeb/bfPixelsDEAD');
|
||||
// animation.addByPrefix('singUP', "BF Dies pixel", 24, false);
|
||||
// animation.addByPrefix('firstDeath', "BF Dies pixel", 24, false);
|
||||
// animation.addByPrefix('deathLoop', "Retry Loop", 24, true);
|
||||
// animation.addByPrefix('deathConfirm', "RETRY CONFIRM", 24, false);
|
||||
// animation.play('firstDeath');
|
||||
|
||||
// addOffset('firstDeath');
|
||||
// addOffset('deathLoop', -37);
|
||||
// addOffset('deathConfirm', -37);
|
||||
// playAnim('firstDeath');
|
||||
// // pixel bullshit
|
||||
// setGraphicSize(Std.int(width * 6));
|
||||
// updateHitbox();
|
||||
// antialiasing = false;
|
||||
// flipX = true;
|
||||
|
||||
script.call("postCreate");
|
||||
}
|
||||
|
||||
public function fixChar(switchAnims:Bool = false, autoInterval:Bool = false)
|
||||
{
|
||||
@:noCompletion var __swappedLeftRightAnims:Bool = false;
|
||||
@:noCompletion var __autoInterval:Bool = false;
|
||||
|
||||
public function fixChar(switchAnims:Bool = false, autoInterval:Bool = false) {
|
||||
if ((isDanceLeftDanceRight = hasAnimation("danceLeft") && hasAnimation("danceRight")) && autoInterval)
|
||||
beatInterval = 1;
|
||||
__autoInterval = autoInterval;
|
||||
|
||||
// alternative to xor operator
|
||||
// for people who dont believe it, heres the truth table
|
||||
// [ a ][ b ][ a!= b ]
|
||||
// [ true ][ true ][ false ]
|
||||
// [ true ][ false ][ true ]
|
||||
// [ false ][ true ][ true ]
|
||||
// [ true ][ true ][ false ]
|
||||
// bros provided evidence :skull:
|
||||
// character is flipped
|
||||
if (isPlayer != playerOffsets && switchAnims)
|
||||
{
|
||||
// character is flipped
|
||||
CoolUtil.switchAnimFrames(animation.getByName('singRIGHT'), animation.getByName('singLEFT'));
|
||||
CoolUtil.switchAnimFrames(animation.getByName('singRIGHTmiss'), animation.getByName('singLEFTmiss'));
|
||||
swapLeftRightAnimations();
|
||||
|
||||
switchOffset('singLEFT', 'singRIGHT');
|
||||
switchOffset('singLEFTmiss', 'singRIGHTmiss');
|
||||
}
|
||||
frameOffset.set(getAnimOffset(getAnimName()).x, getAnimOffset(getAnimName()).y);
|
||||
if (isPlayer)
|
||||
flipX = !flipX;
|
||||
if (isPlayer) flipX = !flipX;
|
||||
__baseFlipped = flipX;
|
||||
}
|
||||
|
||||
var __baseFlipped:Bool = false;
|
||||
var isDanceLeftDanceRight:Bool = false;
|
||||
public function swapLeftRightAnimations() {
|
||||
CoolUtil.switchAnimFrames(animation.getByName('singRIGHT'), animation.getByName('singLEFT'));
|
||||
CoolUtil.switchAnimFrames(animation.getByName('singRIGHTmiss'), animation.getByName('singLEFTmiss'));
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
switchOffset('singLEFT', 'singRIGHT');
|
||||
switchOffset('singLEFTmiss', 'singRIGHTmiss');
|
||||
|
||||
__swappedLeftRightAnims = true;
|
||||
}
|
||||
|
||||
@:noCompletion var __baseFlipped:Bool = false;
|
||||
@:noCompletion var isDanceLeftDanceRight:Bool = false;
|
||||
|
||||
override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
script.call("update", [elapsed]);
|
||||
if (stunned)
|
||||
{
|
||||
if (stunned) {
|
||||
__stunnedTime += elapsed;
|
||||
if (__stunnedTime > 5 / 60)
|
||||
stunned = false;
|
||||
@@ -215,33 +155,20 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
|
||||
private var danced:Bool = false;
|
||||
|
||||
/**
|
||||
* FOR GF DANCING SHIT
|
||||
*/
|
||||
public function dance()
|
||||
{
|
||||
public function dance() {
|
||||
if(debugMode) return;
|
||||
|
||||
var event = EventManager.get(DanceEvent).recycle(danced);
|
||||
script.call("onDance", [event]);
|
||||
if (event.cancelled)
|
||||
return;
|
||||
if (event.cancelled) return;
|
||||
|
||||
switch (curCharacter)
|
||||
{
|
||||
// hardcode custom dance animations here
|
||||
default:
|
||||
if (isDanceLeftDanceRight)
|
||||
{
|
||||
playAnim(((danced = !danced) ? 'danceLeft' : 'danceRight') + idleSuffix, DANCE);
|
||||
}
|
||||
else
|
||||
playAnim('idle' + idleSuffix, DANCE);
|
||||
}
|
||||
if (isDanceLeftDanceRight)
|
||||
playAnim(((danced = !danced) ? 'danceLeft' : 'danceRight') + idleSuffix, DANCE);
|
||||
else
|
||||
playAnim('idle' + idleSuffix, DANCE);
|
||||
}
|
||||
|
||||
public function tryDance()
|
||||
{
|
||||
public function tryDance() {
|
||||
switch (lastAnimContext) {
|
||||
case SING | MISS:
|
||||
if (lastHit + (Conductor.stepCrochet * holdTime) < Conductor.songPosition)
|
||||
@@ -261,96 +188,61 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
* Whenever the character should dance on beat or not. Set to false for `gf`, since the dance animation is automatically handled by PlayState.
|
||||
*/
|
||||
public var danceOnBeat:Bool = true;
|
||||
|
||||
public override function beatHit(curBeat:Int) {
|
||||
script.call("beatHit", [curBeat]);
|
||||
|
||||
if (danceOnBeat && (curBeat + beatOffset) % beatInterval == 0 && !__lockAnimThisFrame)
|
||||
{
|
||||
tryDance();
|
||||
}
|
||||
}
|
||||
|
||||
public override function stepHit(curStep:Int) {
|
||||
public override function stepHit(curStep:Int)
|
||||
script.call("stepHit", [curStep]);
|
||||
// nothing
|
||||
}
|
||||
|
||||
var __reverseDrawProcedure:Bool = false;
|
||||
|
||||
@:noCompletion var __reverseDrawProcedure:Bool = false;
|
||||
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
|
||||
if (__reverseDrawProcedure)
|
||||
{
|
||||
if (__reverseDrawProcedure) {
|
||||
scale.x *= -1;
|
||||
var bounds = super.getScreenBounds(newRect, camera);
|
||||
var bounds:FlxRect = super.getScreenBounds(newRect, camera);
|
||||
scale.x *= -1;
|
||||
return bounds;
|
||||
}
|
||||
return super.getScreenBounds(newRect, camera);
|
||||
}
|
||||
|
||||
public function isFlippedOffsets() {
|
||||
return (isPlayer != playerOffsets) != (flipX != __baseFlipped);
|
||||
public override function isOnScreen(?camera:FlxCamera):Bool {
|
||||
if (debugMode) return true;
|
||||
return super.isOnScreen(camera);
|
||||
}
|
||||
|
||||
var __drawingShadowFrame = false;
|
||||
var __oldColorTransform = new ColorTransform();
|
||||
public function isFlippedOffsets()
|
||||
return (isPlayer != playerOffsets) != (flipX != __baseFlipped);
|
||||
|
||||
public override function draw() {
|
||||
if (!__drawingShadowFrame && shadowFrame != null) {
|
||||
__drawingShadowFrame = true;
|
||||
|
||||
var oldFrame = _frame;
|
||||
var oldPos = FlxPoint.get(frameOffset.x, frameOffset.y);
|
||||
|
||||
__oldColorTransform.copyColorTransform(colorTransform);
|
||||
|
||||
colorTransform.alphaMultiplier = 1;
|
||||
colorTransform.alphaOffset = 0;
|
||||
colorTransform.blueMultiplier = 0;
|
||||
colorTransform.blueOffset = 25;
|
||||
colorTransform.greenMultiplier = 0;
|
||||
colorTransform.greenOffset = 25;
|
||||
colorTransform.redMultiplier = 0;
|
||||
colorTransform.redOffset = 25;
|
||||
|
||||
_frame = shadowFrame.frame;
|
||||
var o = getAnimOffset(shadowFrame.anim);
|
||||
frameOffset.set(o.x, o.y);
|
||||
super.draw();
|
||||
|
||||
_frame = oldFrame;
|
||||
frameOffset.set(oldPos.x, oldPos.y);
|
||||
|
||||
colorTransform.copyColorTransform(__oldColorTransform);
|
||||
|
||||
oldPos.put();
|
||||
|
||||
__drawingShadowFrame = false;
|
||||
}
|
||||
|
||||
if (isFlippedOffsets())
|
||||
{
|
||||
if (isFlippedOffsets()) {
|
||||
__reverseDrawProcedure = true;
|
||||
|
||||
flipX = !flipX;
|
||||
scale.x *= -1;
|
||||
|
||||
super.draw();
|
||||
|
||||
flipX = !flipX;
|
||||
scale.x *= -1;
|
||||
|
||||
__reverseDrawProcedure = false;
|
||||
}
|
||||
else
|
||||
super.draw();
|
||||
} else super.draw();
|
||||
}
|
||||
|
||||
public override function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
|
||||
{
|
||||
public var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
|
||||
public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Force:Bool = true, Reversed:Bool = false, Frame:Int = 0) {
|
||||
var event = EventManager.get(DirectionAnimEvent).recycle(singAnims[direction % singAnims.length] + suffix, direction, suffix, Context, Reversed, Frame, Force);
|
||||
script.call("onPlaySingAnim", [event]);
|
||||
if (!event.cancelled)
|
||||
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
|
||||
}
|
||||
|
||||
public override function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0) {
|
||||
var event = EventManager.get(PlayAnimEvent).recycle(AnimName, Force, Reversed, Frame, Context);
|
||||
script.call("onPlayAnim", [event]);
|
||||
if (event.cancelled)
|
||||
return;
|
||||
if (event.cancelled) return;
|
||||
|
||||
super.playAnim(event.animName, event.force, event.context, event.reverse, event.startingFrame);
|
||||
|
||||
@@ -359,50 +251,65 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
lastHit = Conductor.songPosition;
|
||||
}
|
||||
|
||||
public override function destroy()
|
||||
{
|
||||
public inline function getCameraPosition() {
|
||||
var midpoint:FlxPoint = getMidpoint();
|
||||
var event = EventManager.get(PointEvent).recycle(
|
||||
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
|
||||
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
|
||||
script.call("onGetCamPos", [event]);
|
||||
|
||||
midpoint.put();
|
||||
return new FlxPoint(event.x, event.y);
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
script.call('destroy');
|
||||
script.destroy();
|
||||
super.destroy();
|
||||
|
||||
cameraOffset.put();
|
||||
globalOffset.put();
|
||||
}
|
||||
|
||||
// FlxTrail Stuff for fixing position
|
||||
@:noCompletion var __reverseTrailProcedure:Bool = false;
|
||||
|
||||
var __reverseTrailProcedure:Bool = false;
|
||||
|
||||
/**
|
||||
* When using trails on characters you should do `trail.beforeCache = char.beforeTrailCache;`
|
||||
**/
|
||||
dynamic function beforeTrailCache() {
|
||||
if (isFlippedOffsets())
|
||||
{
|
||||
// When using trails on characters you should do `trail.beforeCache = char.beforeTrailCache;`
|
||||
public dynamic function beforeTrailCache()
|
||||
if (isFlippedOffsets()) {
|
||||
flipX = !flipX;
|
||||
scale.x *= -1;
|
||||
__reverseTrailProcedure = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When using trails on characters you should do `trail.afterCache = char.afterTrailCache;`
|
||||
**/
|
||||
dynamic function afterTrailCache() {
|
||||
if (__reverseTrailProcedure)
|
||||
{
|
||||
// When using trails on characters you should do `trail.afterCache = char.afterTrailCache;`
|
||||
public dynamic function afterTrailCache()
|
||||
if (__reverseTrailProcedure) {
|
||||
flipX = !flipX;
|
||||
scale.x *= -1;
|
||||
__reverseTrailProcedure = false;
|
||||
}
|
||||
|
||||
public function applyXML(xml:Access) { // just for now till i remake the dumb editor
|
||||
gameOverCharacter = Character.FALLBACK_DEAD_CHARACTER;
|
||||
cameraOffset.set(0, 0);
|
||||
globalOffset.set(0, 0);
|
||||
playerOffsets = false;
|
||||
flipX = false;
|
||||
holdTime = 4;
|
||||
iconColor = null;
|
||||
|
||||
animation.destroyAnimations();
|
||||
animDatas.clear();
|
||||
|
||||
__baseFlipped = false;
|
||||
buildCharacter(xml);
|
||||
}
|
||||
|
||||
// Character editor and loading
|
||||
|
||||
public function applyXML(xml:Access) {
|
||||
this.xml = xml; // modders wassup
|
||||
public inline function buildCharacter(xml:Access) {
|
||||
this.xml = xml; // Modders wassup :D
|
||||
sprite = curCharacter;
|
||||
|
||||
if (xml.x.exists("isPlayer")) playerOffsets = (xml.x.get("isPlayer") == "true");
|
||||
if (xml.x.exists("isGF")) isGF = (xml.x.get("isGF") == "true");
|
||||
if (xml.x.exists("x")) globalOffset.x = Std.parseFloat(xml.x.get("x"));
|
||||
if (xml.x.exists("y")) globalOffset.y = Std.parseFloat(xml.x.get("y"));
|
||||
if (xml.x.exists("gameOverChar")) gameOverCharacter = xml.x.get("gameOverChar");
|
||||
@@ -413,7 +320,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
if (xml.x.exists("icon")) icon = xml.x.get("icon");
|
||||
if (xml.x.exists("color")) iconColor = FlxColor.fromString(xml.x.get("color"));
|
||||
if (xml.x.exists("scale")) {
|
||||
var scale = Std.parseFloat(xml.x.get("scale")).getDefault(1);
|
||||
var scale:Float = Std.parseFloat(xml.x.get("scale")).getDefault(1);
|
||||
this.scale.set(scale, scale);
|
||||
updateHitbox();
|
||||
}
|
||||
@@ -431,38 +338,49 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
|
||||
loadSprite(Paths.image('characters/$sprite'));
|
||||
|
||||
animation.destroyAnimations();
|
||||
animDatas.clear();
|
||||
for (anim in xml.nodes.anim)
|
||||
{
|
||||
XMLUtil.addXMLAnimation(this, anim);
|
||||
}
|
||||
|
||||
fixChar(true, !hasInterval);
|
||||
for (attribute in xml.x.attributes())
|
||||
if (!characterProperties.contains(attribute))
|
||||
extra[attribute] = xml.x.get(attribute);
|
||||
|
||||
fixChar(__switchAnims, !hasInterval);
|
||||
dance();
|
||||
}
|
||||
|
||||
public function buildXML(?animsOrder:Array<String>):Xml {
|
||||
var xml = Xml.createElement("character");
|
||||
xml.set("isPlayer", playerOffsets == true ? "true" : "false");
|
||||
xml.set("isGF", isGF == true ? "true" : "false");
|
||||
xml.set("x", Std.string(globalOffset.x));
|
||||
xml.set("y", Std.string(globalOffset.y));
|
||||
xml.set("gameOverChar", gameOverCharacter);
|
||||
xml.set("camx", Std.string(cameraOffset.x));
|
||||
xml.set("camy", Std.string(cameraOffset.y));
|
||||
xml.set("holdTime", Std.string(holdTime));
|
||||
xml.set("flipX", Std.string(flipX));
|
||||
xml.set("icon", getIcon());
|
||||
if (iconColor != null)
|
||||
xml.set("color", iconColor.toWebString());
|
||||
xml.set("scale", Std.string(scale.x));
|
||||
xml.set("antialiasing", antialiasing == true ? "true" : "false");
|
||||
xml.set("sprite", sprite);
|
||||
public static var characterProperties:Array<String> = [
|
||||
"x", "y", "sprite", "scale", "antialiasing",
|
||||
"flipX", "camx", "camy", "isPlayer", "icon",
|
||||
"color", "gameOverChar", "holdTime"
|
||||
];
|
||||
public static var characterAnimProperties:Array<String> = [
|
||||
"name", "anim", "x", "y", "fps", "loop", "indices"
|
||||
];
|
||||
|
||||
for (prop=>val in extra) {
|
||||
xml.set(prop, Std.string(val));
|
||||
}
|
||||
public inline function buildXML(?animsOrder:Array<String>):Xml {
|
||||
var xml:Xml = Xml.createElement("character");
|
||||
xml.attributeOrder = characterProperties.copy();
|
||||
|
||||
if (globalOffset.x != 0) xml.set("x", Std.string(FlxMath.roundDecimal(globalOffset.x, 2)));
|
||||
if (globalOffset.y != 0) xml.set("y", Std.string(FlxMath.roundDecimal(globalOffset.y, 2)));
|
||||
|
||||
if (cameraOffset.x != 0) xml.set("camx", Std.string(FlxMath.roundDecimal(cameraOffset.x, 2)));
|
||||
if (cameraOffset.y != 0) xml.set("camy", Std.string(FlxMath.roundDecimal(cameraOffset.y, 2)));
|
||||
|
||||
if (holdTime != 4) xml.set("holdTime", Std.string(FlxMath.roundDecimal(holdTime, 4)));
|
||||
|
||||
if (flipX) xml.set("flipX", Std.string(flipX));
|
||||
xml.set("icon", getIcon());
|
||||
|
||||
if (gameOverCharacter != Character.FALLBACK_DEAD_CHARACTER) xml.set("gameOverChar", gameOverCharacter);
|
||||
if (iconColor != null) xml.set("color", iconColor.toWebString());
|
||||
|
||||
xml.set("sprite", sprite);
|
||||
if (scale.x != 1) xml.set("scale", Std.string(FlxMath.roundDecimal(scale.x, 4)));
|
||||
if (!antialiasing) xml.set("antialiasing", antialiasing == true ? "true" : "false");
|
||||
|
||||
if (playerOffsets) xml.set("isPlayer", playerOffsets == true ? "true" : "false");
|
||||
|
||||
var anims:Array<AnimData> = [];
|
||||
if (animsOrder != null) {
|
||||
@@ -471,22 +389,32 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
} else
|
||||
anims = Lambda.array(animDatas);
|
||||
|
||||
for (anim in anims)
|
||||
{
|
||||
for (anim in anims) {
|
||||
var animXml:Xml = Xml.createElement('anim');
|
||||
animXml.attributeOrder = characterAnimProperties;
|
||||
|
||||
animXml.set("name", anim.name);
|
||||
animXml.set("anim", anim.anim);
|
||||
animXml.set("loop", Std.string(anim.loop));
|
||||
animXml.set("fps", Std.string(anim.fps));
|
||||
animXml.set("fps", Std.string(FlxMath.roundDecimal(anim.fps, 2)));
|
||||
|
||||
var offset:FlxPoint = getAnimOffset(anim.name);
|
||||
animXml.set("x", Std.string(offset.x));
|
||||
animXml.set("y", Std.string(offset.y));
|
||||
animXml.set("x", Std.string(FlxMath.roundDecimal(offset.x, 2)));
|
||||
animXml.set("y", Std.string(FlxMath.roundDecimal(offset.y, 2)));
|
||||
offset.putWeak();
|
||||
|
||||
if (anim.indices.length > 0)
|
||||
animXml.set("indices", anim.indices.join(","));
|
||||
|
||||
xml.addChild(animXml);
|
||||
}
|
||||
|
||||
for (name => val in extra)
|
||||
if (!xml.attributeOrder.contains(name)) {
|
||||
xml.attributeOrder.push(name);
|
||||
xml.set(name, Std.string(val));
|
||||
}
|
||||
|
||||
this.xml = new Access(xml);
|
||||
return xml;
|
||||
}
|
||||
@@ -494,74 +422,72 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
public inline function getIcon()
|
||||
return (icon != null) ? icon : curCharacter;
|
||||
|
||||
public function getAnimOrder() {
|
||||
public function getAnimOrder()
|
||||
return [for(a in xml.nodes.anim) if(a.has.name) a.att.name];
|
||||
}
|
||||
|
||||
// Getters / Setters
|
||||
|
||||
@:noCompletion private function set_stunned(b:Bool)
|
||||
{
|
||||
@:noCompletion private function set_stunned(b:Bool) {
|
||||
__stunnedTime = 0;
|
||||
return stunned = b;
|
||||
}
|
||||
|
||||
// Backwards Compat
|
||||
|
||||
/**
|
||||
* Interval at which the character will dance (higher number = slower dance)
|
||||
*/
|
||||
// Interval at which the character will dance (higher number = slower dance)
|
||||
@:noCompletion public var danceInterval(get, set):Int;
|
||||
@:noCompletion private function set_danceInterval(v:Int)
|
||||
return beatInterval = v;
|
||||
@:noCompletion private function get_danceInterval()
|
||||
return beatInterval;
|
||||
|
||||
// Statics
|
||||
|
||||
public static function getIconFromCharName(?curCharacter:String) {
|
||||
if(curCharacter == null) return "face";
|
||||
var icon = curCharacter;
|
||||
while(true) {
|
||||
switch (curCharacter) {
|
||||
// case 'your-char': // To hardcode characters icons
|
||||
default:
|
||||
// load xml
|
||||
var xmlPath = Paths.xml('characters/$curCharacter');
|
||||
if (!Assets.exists(xmlPath)) {
|
||||
curCharacter = "bf";
|
||||
continue;
|
||||
}
|
||||
public static var FALLBACK_CHARACTER:String = "bf";
|
||||
public static var FALLBACK_DEAD_CHARACTER:String = "bf-dead";
|
||||
public static function getXMLFromCharName(character:OneOfTwo<String, Character>):Access {
|
||||
var char:Character = null;
|
||||
if (character is Character) {
|
||||
char = cast(character, Character);
|
||||
character = char.curCharacter;
|
||||
}
|
||||
|
||||
var xml = null;
|
||||
var plainXML = Assets.getText(xmlPath);
|
||||
try {
|
||||
var charXML = Xml.parse(plainXML).firstElement();
|
||||
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
|
||||
xml = new Access(charXML);
|
||||
} catch(e) {
|
||||
Logs.trace('Error while loading character ${curCharacter}: ${e}', ERROR);
|
||||
curCharacter = "bf";
|
||||
continue;
|
||||
}
|
||||
var xml:Access = null;
|
||||
while (true) {
|
||||
var xmlPath:String = Paths.xml('characters/$character');
|
||||
if (!Assets.exists(xmlPath)) {
|
||||
character = FALLBACK_CHARACTER;
|
||||
if (char != null)
|
||||
char.curCharacter = character;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (xml.x.exists("icon")) icon = xml.x.get("icon");
|
||||
}
|
||||
var plainXML:String = Assets.getText(xmlPath);
|
||||
try {
|
||||
var charXML:Xml = Xml.parse(plainXML).firstElement();
|
||||
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
|
||||
xml = new Access(charXML);
|
||||
} catch (e) {
|
||||
Logs.trace('Error while loading character ${character}: ${e}', ERROR);
|
||||
|
||||
character = FALLBACK_CHARACTER;
|
||||
if (char != null)
|
||||
char.curCharacter = character;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static function getIconFromCharName(?character:String) {
|
||||
if(character == null) return "face";
|
||||
var icon:String = character;
|
||||
|
||||
var xml:Access = getXMLFromCharName(character);
|
||||
if (xml != null && xml.x.exists("icon")) icon = xml.x.get("icon");
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static function getList(?mods:Bool = false):Array<String> {
|
||||
public static function getList(?mods:Bool = false):Array<String>
|
||||
return [
|
||||
for (path in Paths.getFolderContent('data/characters/', true, mods ? MODS : BOTH))
|
||||
if (Path.extension(path) == "xml") Path.withoutDirectory(Path.withoutExtension(path))
|
||||
if (Path.extension(path) == "xml") CoolUtil.getFilename(path)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
typedef CharacterShadowFrame =
|
||||
{
|
||||
var anim:String;
|
||||
var frame:FlxFrame;
|
||||
}
|
||||
}
|
||||
@@ -210,9 +210,13 @@ class PlayState extends MusicBeatState
|
||||
*/
|
||||
public var canAccessDebugMenus:Bool = true;
|
||||
/**
|
||||
* Wether or not to show the secret gitaroo pause.
|
||||
* Whether or not to show the secret gitaroo pause.
|
||||
*/
|
||||
public var allowGitaroo:Bool = true;
|
||||
/**
|
||||
* Whether or not to bop the icons on beat.
|
||||
*/
|
||||
public var doIconBop:Bool = true;
|
||||
|
||||
/**
|
||||
* Whenever cam zooming is enabled, enables on a note hit if not cancelled.
|
||||
@@ -354,11 +358,19 @@ class PlayState extends MusicBeatState
|
||||
* Camera zoom at which the game lerps to.
|
||||
*/
|
||||
public var defaultCamZoom:Float = 1.05;
|
||||
|
||||
/**
|
||||
* Speed at which the game camera zoom lerps to.
|
||||
*/
|
||||
public var camGameZoomLerp:Float = 0.05;
|
||||
|
||||
/**
|
||||
* Camera zoom at which the hud lerps to.
|
||||
*/
|
||||
public var defaultHudZoom:Float = 1.0;
|
||||
/**
|
||||
* Speed at which the hud camera zoom lerps to.
|
||||
*/
|
||||
public var camHUDZoomLerp:Float = 0.05;
|
||||
|
||||
/**
|
||||
* Zoom for the pixel assets.
|
||||
@@ -1232,12 +1244,13 @@ class PlayState extends MusicBeatState
|
||||
}
|
||||
}
|
||||
|
||||
iconP1.scale.set(lerp(iconP1.scale.x, 1, 0.33), lerp(iconP1.scale.y, 1, 0.33));
|
||||
iconP2.scale.set(lerp(iconP2.scale.x, 1, 0.33), lerp(iconP2.scale.y, 1, 0.33));
|
||||
|
||||
iconP1.updateHitbox();
|
||||
iconP2.updateHitbox();
|
||||
if (doIconBop) {
|
||||
iconP1.scale.set(lerp(iconP1.scale.x, 1, 0.33), lerp(iconP1.scale.y, 1, 0.33));
|
||||
iconP2.scale.set(lerp(iconP2.scale.x, 1, 0.33), lerp(iconP2.scale.y, 1, 0.33));
|
||||
|
||||
iconP1.updateHitbox();
|
||||
iconP2.updateHitbox();
|
||||
}
|
||||
updateIconPositions();
|
||||
|
||||
if (startingSong)
|
||||
@@ -1286,8 +1299,8 @@ class PlayState extends MusicBeatState
|
||||
|
||||
if (camZooming)
|
||||
{
|
||||
FlxG.camera.zoom = lerp(FlxG.camera.zoom, defaultCamZoom, 0.05);
|
||||
camHUD.zoom = lerp(camHUD.zoom, defaultHudZoom, 0.05);
|
||||
FlxG.camera.zoom = lerp(FlxG.camera.zoom, defaultCamZoom, camGameZoomLerp);
|
||||
camHUD.zoom = lerp(camHUD.zoom, defaultHudZoom, camHUDZoomLerp);
|
||||
}
|
||||
|
||||
// RESET = Quick Game Over Screen
|
||||
@@ -1787,11 +1800,14 @@ class PlayState extends MusicBeatState
|
||||
camHUD.zoom += 0.03 * camZoomingStrength;
|
||||
}
|
||||
|
||||
iconP1.scale.set(1.2, 1.2);
|
||||
iconP2.scale.set(1.2, 1.2);
|
||||
if (doIconBop)
|
||||
{
|
||||
iconP1.scale.set(1.2, 1.2);
|
||||
iconP2.scale.set(1.2, 1.2);
|
||||
|
||||
iconP1.updateHitbox();
|
||||
iconP2.updateHitbox();
|
||||
iconP1.updateHitbox();
|
||||
iconP2.updateHitbox();
|
||||
}
|
||||
|
||||
scripts.call("beatHit", [curBeat]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.xml;
|
||||
|
||||
using StringTools;
|
||||
|
||||
/**
|
||||
This class provides utility methods to convert Xml instances to
|
||||
String representation.
|
||||
**/
|
||||
class Printer {
|
||||
/**
|
||||
Convert `Xml` to string representation.
|
||||
|
||||
Set `pretty` to `true` to prettify the result.
|
||||
**/
|
||||
static public function print(xml:Xml, ?pretty = false) {
|
||||
var printer = new Printer(pretty);
|
||||
printer.writeNode(xml, "");
|
||||
return printer.output.toString();
|
||||
}
|
||||
|
||||
var output:StringBuf;
|
||||
var pretty:Bool;
|
||||
|
||||
function new(pretty) {
|
||||
output = new StringBuf();
|
||||
this.pretty = pretty;
|
||||
}
|
||||
|
||||
function writeNode(value:Xml, tabs:String) {
|
||||
switch (value.nodeType) {
|
||||
case CData:
|
||||
write(tabs + "<![CDATA[");
|
||||
write(value.nodeValue);
|
||||
write("]]>");
|
||||
newline();
|
||||
case Comment:
|
||||
var commentContent:String = value.nodeValue;
|
||||
commentContent = ~/[\n\r\t]+/g.replace(commentContent, "");
|
||||
commentContent = "<!--" + commentContent + "-->";
|
||||
write(tabs);
|
||||
write(StringTools.trim(commentContent));
|
||||
newline();
|
||||
case Document:
|
||||
for (child in value) {
|
||||
writeNode(child, tabs);
|
||||
}
|
||||
case Element:
|
||||
write(tabs + "<");
|
||||
write(value.nodeName);
|
||||
|
||||
var attributes:Array<String> = value.attributeOrder;
|
||||
if (attributes == null)
|
||||
attributes = [for (att in value.attributes()) att];
|
||||
|
||||
for (attribute in attributes) {
|
||||
if (!value.exists(attribute) || value.get(attribute).trim() == "") continue;
|
||||
|
||||
write(" " + attribute + "=\"");
|
||||
write(StringTools.htmlEscape(value.get(attribute), true));
|
||||
write("\"");
|
||||
}
|
||||
if (hasChildren(value)) {
|
||||
write(">");
|
||||
newline();
|
||||
for (child in value) {
|
||||
writeNode(child, pretty ? tabs + "\t" : tabs);
|
||||
}
|
||||
write(tabs + "</");
|
||||
write(value.nodeName);
|
||||
write(">");
|
||||
newline();
|
||||
} else {
|
||||
write("/>");
|
||||
newline();
|
||||
}
|
||||
case PCData:
|
||||
var nodeValue:String = value.nodeValue;
|
||||
if (nodeValue.length != 0) {
|
||||
write(tabs + StringTools.htmlEscape(nodeValue));
|
||||
newline();
|
||||
}
|
||||
case ProcessingInstruction:
|
||||
write("<?" + value.nodeValue + "?>");
|
||||
newline();
|
||||
case DocType:
|
||||
write("<!DOCTYPE " + value.nodeValue + ">");
|
||||
newline();
|
||||
}
|
||||
}
|
||||
|
||||
inline function write(input:String) {
|
||||
output.add(input);
|
||||
}
|
||||
|
||||
inline function newline() {
|
||||
if (pretty) {
|
||||
output.add("\n");
|
||||
}
|
||||
}
|
||||
|
||||
function hasChildren(value:Xml):Bool {
|
||||
for (child in value) {
|
||||
switch (child.nodeType) {
|
||||
case Element, PCData:
|
||||
return true;
|
||||
case CData, Comment:
|
||||
if (StringTools.ltrim(child.nodeValue).length != 0) {
|
||||
return true;
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user